On Nov 17, 10:23 pm, "Todd A. Jacobs" <tjacobs-sndr- [email protected]> wrote: > On Tue, Nov 17, 2009 at 01:40:25PM -0800, Eric wrote: > > notes_controller: > > def create @note = > > Property.find(params[:id]).notes.create(params[:note]) ... end > > I'm not sure I'm following this. If I follow a link from a property > view: > > <%= link_to 'New note', new_note_path %> > > how is Property.find(params[:id]).notes.create(params[:note]) going to > find @Property? I don't really understand how that's getting passed > along via params here.
You need to, by one method or another, carry around the id of the property that the note should be added to. One way of this is by using nested routes/resources where your urls would be /properties/123/notes/new or /properties/123/notes (for the create action) (and obviously the corresponding route helpers take a property as an argument) The id of the property ends up in your parameters as params [:property_id]. If you don't use nested routes then it's up to you to tack the property_id on by a method of your choice (add it to the path, use a hidden field etc.) Fred > > -- > "Oh, look: rocks!" > -- Doctor Who, "Destiny of the Daleks" -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.

