Sunday, August 31, 2008

Nested Urls

If you would like to nest resources, for example:

http://localhost:3000/school_levels/1/school_level_specifications:

You will need to do the following:

  1. Setup your routes file
  2. Setup your models so that they describe the relationship
  3. Setup the nested controller (school_level_specifications) to grab an instance of the parent object (school_levels/1).









Here's some good resources on nesting urls (including how form_for gets modified)
http://adamblog.heroku.com/past/2007/12/20/nested_resources_in_rails_2/

If you want to use link_to, use the following:
<%= link_to 'Show', [@daily_content, vocabulary] %>


If you want to add extra information in a form_for use a text_field_tag. If that tag is in a nested resource, you can access the information using two levels of the params variables. See below.

If you use nested resources, a

<%= text_field_tag 'user[firstname]' %>

in your form, will result in

params[:user][:firstname]

in your controller.

To find the naming scheme use: rake routes

No comments: