Forum: Ruby on Rails Possible to change controller's default action?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
cool_screen_name90001 (Guest)
on 2005-11-12 13:50
(Received via mailing list)
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
francois.beausoleil (Guest)
on 2005-11-12 13:50
(Received via mailing list)
Hi !

2005/11/11, CSN <removed_email_address@domain.invalid>:
> 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
jamis (Guest)
on 2005-11-12 13:50
(Received via mailing list)
On Nov 11, 2005, at 10:27 PM, Francois B. wrote:

> Hi !
>
> 2005/11/11, CSN <removed_email_address@domain.invalid>:
>> 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"

- Jamis
cool_screen_name90001 (Guest)
on 2005-11-12 13:50
(Received via mailing list)
Right, but I have different templates (displaying
different stuff) for index and list.

csn
jarkko (Guest)
on 2005-11-14 09:59
(Received via mailing 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
cool_screen_name90001 (Guest)
on 2005-11-14 12:06
(Received via mailing list)
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. <removed_email_address@domain.invalid> 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
jarkko (Guest)
on 2005-11-14 12:06
(Received via mailing list)
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 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).

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
cool_screen_name90001 (Guest)
on 2005-11-14 12:19
(Received via mailing list)
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. <removed_email_address@domain.invalid> 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. <removed_email_address@domain.invalid> 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
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


craig




__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
jarkko (Guest)
on 2005-11-14 12:28
(Received via mailing list)
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. http://wiki.rubyonrails.com/rails/pages/NamedRoutes

>
> 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
This topic is locked and can not be replied to.