seungpyo.com

to make the cloud sky happy, do we look up at it and rain? 
« Back to blog

Ruby on Rails [RoR]: Figuring out *_url and *_path for two-worded model/controller name

Totally a nerd posting but I'm just getting started on Ruby on Rails and it's been driving me insane just to try and figure out what the helper paths would be if I had say for instance an Rsvp model that had a many relation with a RsvpGuests model.

Turns out the syntax works out like this:

[first model name all lower case singular]_[second model name all lower case, camel cased words are separated by an underscore]_path

It might be hard to parse this but basically it looks like this for the Rsvp and RsvpGuests models where Rsvp has many RsvpGuests:
rsvp_rsvp_guests_path(@rsvp)

You could imagine other scenarios where this might come in handy to know when working on Rails.

FOLLOWUP:
On subsequent model pages (in this case RsvpGuests), here are the other _url and _paths that get generated:

rsvp_rsvp_guest_path(@rsvp, guest) #show
edit_rsvp_rsvp_guest_path(@rsvp, guest) #edit
new_rsvp_rsvp_guest_path #new

Comments (0)

Leave a comment...