how do I create a custom route in rails where I pass the id of an existing Model?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-06-11T04:01:41Z Indexed on 2010/06/11 6:33 UTC
Read the original article Hit count: 173

Filed under:
|

I created the following route:

  map.todo "todo/today",
            :controller => "todo",
            :action => "show_date"

Originally, the 'show_date' action and associated view would display all the activities associated for that day for all the Campaigns.

This ended up being very slow on the database...it would generate roughly 30 records but was still slow.

So, I'm thinking of creating a partial that would first list the campaigns separately.

If someone clicked on a link associated with campaign_id = 1, I want it to go to the following route:

todo/today/campaign/1

Then I would like to know how to know that the '1' is the campaign_id in the controller and then just do its thing.

The reason I want a distinct URL is so that I can cache this list. I have to keep going back to this and it's slow.

NOTE: It's possibly the problem actually is that I've written the queries in a slow way and sqlite isn't representative of how it will be in production, in which case this work-around is unnecessary, but right now, I need a way to get back to the whole list quickly.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about routes