Repository is archived
No commit activity in last 3 years
No release in over 3 years
Enables polls on pages. Uses cookies instead of sessions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Polls Extension

This is a significant fork of the original at https://github.com/nuex/radiant-polls-extension (“Web polls for Radiant CMS.”)

Differences in this Fork

  • Uses cookies instead of sessions to trace poll responses.
    • This limits the occurrence of multiple responses from the same respondent, thus skewing poll results
    • It also means that we will not automatically expire caches on pages with polls, thus improving overall performance. Instead the server will send both the poll and response data, and client side javascript will read cookies to determine which to display
  • Uses poll_check.js to read cookies, determining if this user has submitted response to this poll yet
  • Switched views from erb to haml
  • Uses radiant-cache_by_page-extension, in order to set shorter cache times on pages with polls

Installation

Using Bundler:

  • add this to your Gemfile
    gem "radiant-polls-extension", :git => "https://github.com/avonderluft/radiant-polls-extension.git"
  • rake radiant:extensions:polls:migrate
  • rake radiant:extensions:polls:update
  • bundle

Usage

  • Modify your Radiant Layouts to include:
    • inside the head tag: <script src="/javascripts/poll_check.js" type="text/javascript" charset="utf-8"></script>
    • modify the body tag thus: <body onLoad="checkForPoll();">
  • Create a polls snippet, something like this:
  <r:poll>
    <div id="poll">
      <div class="title">Poll of the Week</div>
      <div id="poll_<r:id/>" class="content">
        <h2><r:title/></h2>
        <div id="poll_<r:id/>_unsubmitted" style="display:none">
          <r:form> 
            <ul>
              <r:options:each><li><r:input /> <r:title /></li></r:options:each>
            </ul>
            <br />
            <input type="submit" name="poll[submit]" value="Submit" onclick="return checkRadioSelection('poll_form','response_id');" /> 
          </r:form>
        </div>

        <div id="poll_<r:id/>_submitted" style="display:none">
          <table>
            <tr>
              <th align="left">Answers</th>
              <th align="left">Results</th>
            </tr>
            <r:options:each>
              <tr>
                <td><r:title /></td>
                <td><r:number_responses /> (<r:percent_responses />%)</td>
              </tr>
            </r:options:each>
          </table>
        </div>
      </div>
    </div>
  </r:poll>

If polls are defined with a start date, then the current poll (defined as the
poll that has the latest start date that is no later than the current date) can
be accessed without the use of the title attribute (i.e., …).

Poll “archives” can also be listed, using pagination via the will_paginate plugin.

Answer Result
(%)

To do

  • the polls (archives) are not working in some instances

Note and Caveats

If you are using the Oracle Enhanced Adapter, you may want to add this to your environment.rb, in the after_initialize block:
  1. By default, OracleEnhancedAdapter typecasts all columns of type DATE to Time or DateTime.
  2. This will force DATE values with hour, min and secs equal to 0 to be typecasted to Date.
    ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = true
  3. The above can obviously cause problems, therefore this is to be preferred,
  4. since it will typecast to DATE, only columns with “date” in their name (e.g. “creation_date“)
    ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true

Acknowledgements

  • Thanks to David Coto (http://github.com/davec) for the many enhancements and specs.
  • The date picker uses Dan Webb’s LowPro library and its associated date_selector
    behavior.