I’m using simple_form and i have a select menu with 3 values, which get printed to the index. I want to know the correct and best way to get the value that the users sets, and then do a count of how many of the 3 different choices there currently are.
I’m new to ruby so this is a big learning curve and any help will be appreciated.
In my _form.html.erb
<%= f.input :menu, :as => :select, :collection => [ "Chocolate", "Cake", "Custard"] %>
My Index.html.erb
<td><%= reply.menu %></td>
db
class CreateReplies < ActiveRecord::Migration
def change
create_table :replies do |t|
t.string :name
t.integer :menu
t.boolean :rsvp, :default => false
t.timestamps
end
end
end
So roll with something like the following:
And then since you’re using SimpleForm:
Then everything else is for the most part automated for you (i.e. when you create/update a reply it’ll grab the posted menu_id and assign it accordingly.
If I were you, I’d dig into http://ruby.railstutorial.org/. It’s an excellent resource.
Update: forgot about your view display (if you’re trying to display the name of the menu you selected – if you’re trying to display an entire menu, that’s a whole other different scenario):