ruby on rails - form_for, url parameter based on parent's id -


i have routes setup fine , working follows:

myapp::application.routes.draw   resources :meal     resources :entre, :side, :desert   end end 

in meal index view, generate, through bunch of partials :entre form follows

<%= div_for meal %>   <tr>     <td> <%= link_to "meal #{meal.id}", meal %> </td>     <td> <div class ="comment"><%= meal.comment %></div></td>   <td></td>     <td><div class ="edit">         <%= link_to 'edit', edit_meal_path(meal) %>         <%= link_to 'destroy', meal, method: :delete, remote: true, data: { confirm:     'are y     </div></td>     <td><div class ="vmaction">         <%= form_for(meal.entres.new(params[:id])) |f| %>         <%= f.textfield :choice %>         <%= f.submit "submit" %>       <% end %>       </div></td>   </tr> <% end %> 

as can see above calling view object in line

<%= form_for(meal.entres.new(params[:id])) |f| %> 

i trying figure out how add in url parameter, based on url, _entres_ controller know meal_id entre being submited for...

i want form generate submit url along lines of when submitting entre meal_id=3

http://website/meal/3/entres/new 

thanks

you need provide meal along new entre in form_for. these rails build url meal_id in route.

something this:

<%= form_for([meal, meal.entres.new]) |f| %> 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -