so have following form create new restaurant instance. in design every restaurant belongs city. in form below created a dropdown give user flexibility chose city of restaurant want change that. way add restaurant in application through page of city. once user in city's page pretty obvious wants add restaurant city, not other one. how modify new restaurant belongs city user wants add restaurant to. in other words if user clicked add new restaurant button in new york city page want form able add new restaurant new york city.
<%= form_for(@restaurant) |f| %> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div> <div class="field"> <%= f.label :adress %><br /> <%= f.text_field :adress %> </div> <div class="field"> <%= f.label :review %><br /> <%= f.text_field :review %> </div> <div class="field"> <%= f.label :city %><br /> <%= f.collection_select :city_id, city.all, :id, :name %> </div> <div class="actions"> <%= f.submit %> </div> <% end %>
add hidden_field
tag, pass city id url param, populate hidden field using params[:id]
.
Comments
Post a Comment