Take the 2-minute tour ×

(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 %>  
    <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 class='box' >"<strong>It grinds our gears </strong><%=h grinder.grinder %>"</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 }
    format.html { render :action => "new" }
    format.xml  { render :xml => @vote.errors, :status => :unprocessable_entity }

but anytime I try to vote, I get the following error. http://grab.by/6EiQ

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Fixed it guys, turns out that last migration I did didn't work... So I had to fix it, and do the migration.

share|improve this answer

how's the relation between the vote and grinder specified in the models?

it's passing a voter_choice that is not part of the vote model. The choice is part tho

In your view change:

from <%= d.hidden_field :voter_choice, :value => "down" %>
to <%= d.hidden_field :choice, :value => "down" %>
share|improve this answer
vote.rb 'belongs_to :grinder' grinder.rb 'has_many :votes', and I changed the view already, same rror. Thanks though. –  Rickmasta Oct 1 '10 at 5:04
from console if u do: v=Vote.new;v.inspect –  CLod Oct 1 '10 at 5:09

Your Answer


