addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Nash.rb Message Board › ResourcesController question

ResourcesController question

Daniel N.
user 8479725
Nashville, TN
Post #: 5
Desired route is lbc_action_plan/:plan_id/step/:step_id/a­ction/:action_id, in which step and action actually refer to lbc_ap_step and lbc_ap_action (see below has_many definitions), respectively.

For a simpler route, lbc_action_plan/:plan_id/step/:step_id, the resources controller definition is as follows:
resources_controller_for :steps, :class => LbcApStep, :in => :lbc_action_plan

Any ideas about how to define the resources controller line for the desired route?

LbcActionPlan defines:
has_many :steps,
:class_name => 'LbcApStep',
:dependent => :destroy

LbcApStep defines:
has_many :actions,
:class_name => 'LbcApAction',
:dependent => :destroy
Daniel N.
user 8479725
Nashville, TN
Post #: 6
Looks like this does it:

map_enclosing_resource :step, :class => LbcApStep, :segment => :steps, :key => :step_id
resources_controller_for :actions, :class => LbcApAction, :only => [:create, :update, :destroy]

Based on the examples, I would have thought that "map_enclosing_resource :steps, :class => LbcApStep, :key => :step_id" would have done it, but that creates a variable named @steps.
Daniel N.
user 8479725
Nashville, TN
Post #: 7
Just in case anyone refers to this later: don't make any models or named has_many relationships "actions". This runs into trouble with the Rails routing "action". This is a shame because in a current project, users maintain lists of actions that they need to take. I'm renaming these references and corresponding routes to "lbc_actions".
Powered by mvnForum

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy