form for - Rails form_for select default option -


i have form_for select options being defined within model. trying display placeholder option cannot figure out how to.

the model:

class factoid < activerecord::base   attr_accessible :description, :name, :title    validates_presence_of :description, :name, :title   validates_uniqueness_of :title     names = "angela", "geordie", "jared", "jennifer", "kevin", "matthew", "oscar", "owen", "regina", "todd", "vaibhavi", "zack"     unransackable_attributes = ["id", "updated_at"]    def self.ransackable_attributes auth_object = nil     (column_names - unransackable_attributes) + _ransackers.keys   end  end 

the form:

<%= form_for @factoid, :html => { :class => 'form-horizontal' } |f| %>   <div class="control-group">     <%= f.label :title, :class => 'control-label' %>     <div class="controls">       <%= f.text_field :title, :class => 'text_field' %>     </div>   </div>   <div class="control-group">     <%= f.label :description, :class => 'control-label' %>     <div class="controls">       <%= f.text_area :description, :class => 'text_area' %>     </div>   </div>   <div class="control-group">     <%= f.label :name, :class => 'control-label' %>     <div class="controls">       <%= f.select :name, :collection => factoid::names %>     </div>   </div>    <div class="form-actions">     <%= f.submit nil, :class => 'btn btn-primary' %>     <%= link_to t('.cancel', :default => t("helpers.links.cancel")),                 factoids_path, :class => 'btn' %>   </div> <% end %> 

the second issue dropdown menu displaying word "collection" @ top of (see screenshot below). how read of that. ideally want have dropdown menu placeholder of "names" displayed @ top when dropdown menu opened. screenshot of issue

for text field try like:

<%= f.text_field :title, :class => 'text_field', value: 'my_default_value' %> 

for select try:

<%= f.select :name, factoid::names %> 

see the docs select , the rails guide typical usage (i think method i've shown not work upon submitting form, see guides linked explanation, i'm not sure though).


Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -