I have the following in a partial in a Rails 3.2 app using formtastic gem
<%= f.semantic_fields_for :bucket do |bucket| %>
<%= bucket.inputs do %>
<%= bucket.input :bucket_name, :collection => @buckets,
:include_blank => false %>
<%= bucket.input :sub_directory, :collection =>
@buckets.first.paths,
:include_blank => false %>
<% end %>
<% end %>
right now in my controller I can get :bucket_name and the value is ==
to an integer, In my case I only have one item in my collection but it is giving me a value of 2. My guess is this is the ID value of the object.
it’s important that I get the actual :name string value of the object
that is selected in the collection. I am not sure how to do this. so
let’s say the item I select has a label of “my label” and it’s the 3rd
item in the collection. how would I grab the value “my label”.
By default, select inputs will use the
idattribute of the model as thevalueattribute of the<option>tags, and it ties various methods on the object for the contents of the option tag such asto_label,name, andto_s.You can change both with the
:member_valueand:member_labeloptions respectively (these were called:value_methodand:label_methodin older versions.The details of each option are in the documentation for the select input:
http://rdoc.info/github/justinfrench/formtastic/Formtastic/Inputs/SelectInput