Module PollsHelper
In: app/helpers/polls_helper.rb

Methods

Public Instance methods

Render the poll

[Source]

    # File app/helpers/polls_helper.rb, line 4
 4:   def current_poll(opthash={})
 5:     poll = @poll || opthash[:poll]
 6:     user = current_user
 7:     
 8:     opthash[:in_place] ||= false
 9:     opthash[:redirect] ||= poll_url(poll.id)
10:     
11:     cookie_name = poll.cookie_name
12: 
13:     # Check for poll existance
14:     if poll.blank?
15:       render :file => "#{polls_view_dir}/poll_not_found.rhtml"
16:     else
17:       # poll exists confirmed
18:       # Now, check user existance
19:       unless !logged_in? && poll.target == Poll::TARGET_LOGGED_USER
20:         # Ask if the conditions are met to show the poll
21:         if user_can_see_poll?(poll, user)
22:           now=Time.now
23:           if user_has_voted_poll?(poll, user)
24:             render :file => "#{polls_view_dir}/already_voted.html.erb", :locals => { :poll => poll }        
25:           elsif poll.outdated?
26:             render :file => "#{polls_view_dir}/poll_outdated.rhtml", :locals => { :poll => poll }
27:           else
28:             render :file => "#{polls_view_dir}/show_poll.html.erb",
29:                    :locals => { :poll => poll, :redirect => opthash[:redirect]}        
30:           end
31:         end
32:       else
33:         # No user found in session & poll configured JUST for USERs (Not anonymous)
34:         render :file => "#{polls_view_dir}/user_not_logged.rhtml"
35:       end
36:     end
37:   end

Mostrar los resultados con el nuevo diseño

[Source]

    # File app/helpers/polls_helper.rb, line 62
62:   def poll_results(opthash = { } )
63:     if @poll
64:       poll = @poll
65:     elsif opthash[:poll]
66:       poll = opthash[:poll]
67:     else
68:       poll_name = opthash[:poll_name] or poll_name = session[:last_poll]
69:       poll = Poll.find(:first, :conditions => ["name = ? ", poll_name]) 
70:     end 
71: 
72:     unless poll.blank?
73:       question = poll.title
74:       answers = poll.options
75:       render :file => "#{polls_view_dir}/show_results.html.erb",
76:              :locals => { :poll => poll, :answers => answers }.merge(opthash)
77:     else
78:       render :file => "#{polls_view_dir}/poll_not_found.html.erb"
79:     end
80:   end
 Renders the poll results

 OBSOLETO

[Source]

    # File app/helpers/polls_helper.rb, line 41
41:   def poll_results_old(opthash = { } )
42:     if @poll
43:       poll = @poll
44:     elsif opthash[:poll]
45:       poll = opthash[:poll]
46:     else
47:       poll_name = opthash[:poll_name] or poll_name = session[:last_poll]
48:       poll = Poll.find(:first, :conditions => ["name = ? ", poll_name]) 
49:     end 
50: 
51:     unless poll.blank?
52:       question = poll.title
53:       answers = poll.options
54:       render :file => "#{polls_view_dir}/show_results.html.erb",
55:              :locals => { :poll => poll, :answers => answers }.merge(opthash)
56:     else
57:       render :file => "#{polls_view_dir}/poll_not_found.html.erb"
58:     end
59:   end

[Source]

    # File app/helpers/polls_helper.rb, line 82
82:   def poll_vote_link(poll, user)
83:     if controller.controller_path.match(/admin\/polls/) && current_user && current_user.is_admin?
84:        txt = ""
85:     else
86:       txt = if user_has_voted_poll?(poll, user)
87:         content_tag(:li, t('polls.Ya_has_votado'), :class => "already_voted")
88:       elsif poll.outdated?
89:         content_tag(:li, t('polls.Caducada'), :class => "outdated")
90:       else
91:         content_tag(:li, link_to("#{t('polls.Votar')}", poll_path(poll)), :class => "vote_link")
92:       end
93:     end
94:     
95:     txt
96:   end

[Validate]