1 Reply Latest reply on Feb 12, 2013 6:49 AM by Gerbrand Stap

    Invoking "create" in one model from "show" in another.

      I am hoping this is a simple question. I have a pair of models - Deliverylist and Delivery. What I want to do is allow the user to select one of the records in the deliverylist and then be taken to a screen where a delivery record can be created using some of the info from the selected item. It's not a parent-child relationship. The delivery list is read-only and a single delivery needs to be created from each entry on that list. I just need a bit of help in the syntax of the action that gets from one method in one model to one in another.

        • Re: Invoking "create" in one model from "show" in another.
          Gerbrand Stap

          At some point you will probably have a link in a Deliverylist view which links to a Delivery. The url for this link can be created using the url_for method and would look something like this:

          url_for :controller => :Delivery, :action => :create, :query => { :deliverylist_id => deliverylist.object }


          Clicking on this link invokes the create method in the Delivery controller and @params will contain the deliverylist_id:

          def create

             list_id = @params[ 'deliverylist_id' ]

             list = Deliverylist.find( list_id )

             # Enter logic here