Is it possible to change a controller’s default action
- say from “index” to “list”?
mydomain.com/item (I want it to “list” rather than
“index”)
thanks
csn
Is it possible to change a controller’s default action
mydomain.com/item (I want it to “list” rather than
“index”)
thanks
csn
Hi !
2005/11/11, CSN [email protected]:
Is it possible to change a controller’s default action
- say from “index” to “list”?
Redirect to :list, or render :list should do it !
If you look at scaffolded code, the second solution is the one used.
Hope that helps !
François
Right, but I have different templates (displaying
different stuff) for index and list.
csn
On Nov 11, 2005, at 10:27 PM, Francois B. wrote:
Hi !
2005/11/11, CSN [email protected]:
Is it possible to change a controller’s default action
- say from “index” to “list”?
Redirect to :list, or render :list should do it !
If you look at scaffolded code, the second solution is the one used.
You can also set up a route:
map.connect “special/:action”, :controller => “special”, :action
=> “list”
On 12.11.2005, at 10.15, CSN wrote:
Right, but I have different templates (displaying
different stuff) for index and list.
So you have both actions, index and list, that do different things.
However, you don’t want the action index to be the default one. Am I
right?
I don’t really understand why, since index is the name for a
default file of a “folder”. If you use page caching, you will
probably run into trouble for this exact reason, even if you use the
trick I’m about to tell you. So caveat emptor.
Put this into your routes:
map.connect “special/”, :controller => “special”, :action => “list”
//jarkko
Well, I just wanted my URLs to be as so:
mysite.com → item’s index action (which has different
queries and layout than ‘list’)
mysite.com/items → item’s list action
mysite.com/item/id → item’s show action
and there are other URLs:
mysite.com/member → member’s index/show action (uses
session)
mysite.com/members → member’s list action
This is likely achievable with routes, and I briefly
tried, but it became complicated (I didn’t know there
would be caching issues either, which I haven’t gotten
into yet).
csn
— Jarkko L. [email protected] wrote:
right?
Redirect to :list, or render :list should do it !
If you look at scaffolded code, the second
solution
is the one used.Hope that helps !
François
craig
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
On 14.11.2005, at 11.39, CSN wrote:
mysite.com/member → member’s index/show action (uses
session)
mysite.com/members → member’s list actionThis is likely achievable with routes, and I briefly
tried, but it became complicated (I didn’t know there
would be caching issues either, which I haven’t gotten
into yet).
There shouldn’t be any issues with the url’s described above. They’re
just url’s and you can map them to controllers/actions using routes.
What do you mean by it becoming complicated? If you want that the
url’s in your app behave in some other way than the
normal :controller/:action/:id, you need to tell it to Rails. It
can’t AFAIK read your mind (yet).
So, here we go, nothing special or extremely complicated:
map.connect “”, :controller => “item”, :action => “index”
map.connect “items”, :controller => “item”, :action => “list”
map.connect “item/:id”, :controller => “item”, :action => “show”
map.connect “member”, :controller => “member”, :action => “index” #
You don’t really need this, this obeys the standard Rails convention
map.connect “members”, :controller => “member”, :action => “list”
You might also want to take a look at named routes.
//jarkko
On 14.11.2005, at 12.16, CSN wrote:
Cool, thanks. Is there a URL which has documentation
for ‘named routes’? There doesn’t appear to be
anything map/route related at api.rubyonrails.org
(figured it’d be ActionController::Routes or
something).
Sorry, forgot that. Peak Obsession
And in what release is mind-reading planned?
There is a debate going on on whether that would make Rails a bit too
‘opinionated’. But we’ll see.
//jarkko
Cool, thanks. Is there a URL which has documentation
for ‘named routes’? There doesn’t appear to be
anything map/route related at api.rubyonrails.org
(figured it’d be ActionController::Routes or
something).
And in what release is mind-reading planned?
thanks
csn
— Jarkko L. [email protected] wrote:
mysite.com/item/id → item’s show action
tried, but it became complicated (I didn’t know
want that the
“index”
:action => “list”
— Jarkko L. [email protected] wrote:However, you don’t want the action index to be
probably run into trouble for this exact reason,If you look at scaffolded code, the second
–
Jarkko L.
http://jlaine.net
http://odesign.fi
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
craig
Yahoo! Mail - PC Magazine Editors’ Choice 2005
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs