forms - Is there a way to set a distinct ID and name for a text_field in Rails 2? -
i've got rails 2 site i'm trying add form handler to, i'm running problems converting html form fields form handler fields.
the form code begins with:
<% form_for @newsavedmap, :html=>{:id=>'createamap'} |f| %>
i keep getting errors when try things
<%= text_field :newsavedmap, :html=>{ :value => 'new map', :name=>'newsavedmapname', :id=> 'savedmap_name', :size => '30' } %>
error:
actionview::templateerror (wrong number of arguments (1 2)) on line #284 of app/views/layouts/maptry.html.erb:
here fields. how can convert these form handler fields in rails 2?
<input id="savemap_name" name="newsavedmapname" size="30" type="text" value="new map"></p> <select id="startdrop" name="startthere"> <options here> </select> <select multiple id="waypoints" class="mobile-waypoints-remove" name="waypointsselected[]"> <options here> </select>
thanks can provide!
edit 1 error code text_field
using bigxiang's approach, get
processing newsavedmapscontroller#create (for ip @ date time) [post] parameters: {"endhere"=>"", "endthere"=>"sample address 1", "newsavedmap"=>{"newsavedmapname"=>"test map"}, "startthere"=>"sample address 2", "starthere"=>"", "optimize"=>"on"} activerecord::unknownattributeerror (unknown attribute: newsavedmapname)
the line "newsavedmap"=>{"newsavedmapname"=>"test map"} should read
"newsavedmapname"=>"test map"
how can this? controller starts with:
def create @newsavedmap = newsavedmap.new(params[:newsavedmap]) @newsavedmap.name = params[:newsavedmapname]
try this:
<% form_for @newsavedmap, :html=>{:id=>'createamap'} |f| %> <%= f.text_field :newsavedmapname :id=>"savemap_name", :size=>30, :value=>"new map"%> <%= f.select :startthere, your_collections, {}, {:id=>"startdrop"}%> <%= f.select :waypointsselected, your_collections, {}, {:id=>"waypoints", :class=>"mobile-waypoints-remove", :multiple => true}%> <% end %>
make sure your_collections should array ['a', 'b', 'c'] or [['name1', id1],['name2', id2],['name3', id3]].
if persist parameter "newsavedmapname"=>"test map", try this:
<% form_for @newsavedmap, :html=>{:id=>'createamap'} |f| %> <%= text_field_tag :newsavedmapname, "new map", :id=>"savemap_name", :size=>30%> <%= select_tag :startthere, options_for_select(your_collections), {:id=>"startdrop"}%> <%= select_tag :waypointsselected, options_for_select(your_collections), {:id=>"waypoints", :class=>"mobile-waypoints-remove", :multiple => true}%> <% end %>
but don't understand why not use parameter's name same column's name. example, see newsavedmap model has column named "name". can use directly
<% form_for @newsavedmap, :html=>{:id=>'createamap'} |f| %> <%= f.text_field :name , :value=>"new map" %> <% end %>
in controller , can delete line @newsavedmap.name = params[:newsavedmapname]
def create @newsavedmap = newsavedmap.new(params[:newsavedmap]) if @newsavedmap.save ####### end end
Comments
Post a Comment