I have three models: Page, Section, and Block. A Page has many Sections, and a Section has many Blocks. I'm trying to write it in such a way where the Page view has a form for creating new Sections, and the Section view has one for creating Blocks.
My problem is passing the page_id
from the Page view to the section#create method; I'm not sure how it's done. In order to be RESTful, do I have to include the parent associations in the URL (i.e. a monster URL like www.mydomain.com/pages/1/sections/3/blocks/5
) so I can get the id for a new query, and then do something like this?
def create
@page = Page.find(params[:page_id])
@section = @page.sections.build(section_params)
I've been reading this (http://ruby.railstutorial.org/), and it comes close to explaining a use case like mine, but I'm stuck. I'm sure there's a "Rails Way" of building CRUD routes where each resource is nested inside the next; can anyone enlighten me?