(Sorry for long post) Ok guys, so I'm having some issues with something I'm trying, I've been trying to fix it for a long time now, and It's now time to ask for help.
Ok, so I have these "grinders", and I want a user to vote for each one,
I did two scaffolds:
grinder grinder:string posted_timestamp:datetime poster_ip:string votes_up:integer
votes_down:integer
vote grinder_id:integer choice:string voter_ip:string
So I created this as the grinders index
<% @grinders.each do |grinder| %>
<div id="main">
<div style="float:left; height:80px; width:50px">
<div class='up'>
<% form_for(@vote) do |u| %>
<%= u.hidden_field :grinder_id, :value => grinder.id %>
<%= u.hidden_field :choice, :value => "down" %>
<%= u.submit 'Create' %>
<% end %>
</div>
<center><%=h grinder.votes_up - grinder.votes_down %></center>
<div class='down'>
<% form_for(@vote) do |d| %>
<%= d.hidden_field :grinder_id, :value => grinder.id %>
<%= d.hidden_field :choice, :value => "down" %>
<%= d.submit 'Create' %>
<% end %>
</div>
</div>
<div class='box' >"<strong>It grinds our gears </strong><%=h grinder.grinder %>"</div>
</div>
</div>
<% end %>
The Grinders index page looks like this, http://grab.by/6Eik
I also added @vote = Vote.new
to the index method of the grinders controller
..
And in the votes controller
I modified the create method a bit.
def create
@vote = Vote.new(params[:vote])
@grinder.voter_ip = request.remote_ip
respond_to do |format|
if @vote.save
format.html { redirect_to(@vote, :notice => 'Vote was successfully created.') }
format.xml { render :xml => @vote, :status => :created, :location => @vote }
else
format.html { render :action => "new" }
format.xml { render :xml => @vote.errors, :status => :unprocessable_entity }
end
end
end
but anytime I try to vote, I get the following error. http://grab.by/6EiQ