Using record variable in routes

I have two models in my application. One model is the project and it
has many images. I’d like to configure my routes so the URLs show the
names of the projects and images instead of the IDs.

For example:


would display detail about a specific project where “brooklyn-loft” is a
variable and unique for each project record,



would display detail about an image that belongs to the project and
“master-bathroom–2” is a variable and unique for each image record.

Any ideas on how I would setup my routes to dynamically generate like




map.connect “/projects/:project_slug/:image_slug”, :controller =>
“images”, :action => “show”


def show
@project = Project.find_by_slug(params[:project_slug])
@image = Image.find_by_slug(params[:image_slug])


On Mar 8, 8:45 pm, David L. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs