Commit d63bb085 authored by Michael Vernier's avatar Michael Vernier

Updated vote and index functions of poll controller. Added poll rendering. Removed vote rendering

parent 0590ae16
......@@ -3,8 +3,15 @@ class PollsController < ApplicationController
def index
@polls = Poll.all
end
def vote
poll = Poll.find( params[ :id ] )
poll.vote( params[ :answer ] )
if poll.save
flash[ :notice ] = 'Vote saved.'
end
redirect_to :action => 'index'
end
end
<h2>PollsController#index</h2>
<h2>Polls</h2>
<% @polls.each do |poll| %>
<p>
<%= poll.question %>?
<%= link_to 'Yes', { :action => 'vote', :id => poll[:id], :answer => 'yes' }, :method => :post %> (<%= poll.yes %>) /
<%= link_to 'No', { :action => 'vote', :id => poll[:id], :answer => 'no' }, :method => :post %> (<%= poll.no %>)
</p>
<% end %>
<h2>PollsController#vote</h2>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment