Re: Routes: How would default routes be defined manually?

Ahmy Yulrizka
Mon, 20 Dec 2010 08:37:26 -0000

when you specify route inside resource, AFAIK
if you specify the route inside "collection", rails will always append
ies
like priorities
if you specify the route inside "member", rails will always use the
singular
word liake priority

so in that way, one solution (but i dont know if this the best way to do
it). is define custom route outside the resource block. such as.

  resources :priorities do
  end

  get ''/priorities/add'' =>
''priorities#new'', :as => :add_priority

this will give routes

   priorities GET    /priorities(.:format)
{:action=>"index",
:controller=>"priorities"}
              POST   /priorities(.:format)
{:action=>"create",
:controller=>"priorities"}
 new_priority GET    /priorities/new(.:format)
{:action=>"new",
:controller=>"priorities"}
edit_priority GET    /priorities/:id/edit(.:format)
{:action=>"edit",
:controller=>"priorities"}
     priority GET    /priorities/:id(.:format)
{:action=>"show",
:controller=>"priorities"}
              PUT    /priorities/:id(.:format)
{:action=>"update",
:controller=>"priorities"}
              DELETE /priorities/:id(.:format)
{:action=>"destroy",
:controller=>"priorities"}
 add_priority GET    /priorities/add(.:format)
{:action=>"new",
:controller=>"priorities"}

btw, im using rails 3, i don''t know if there''s different with
the 2.x
version

Ahmy Yulrizka


On Mon, Dec 20, 2010 at 2:50 PM, bourne
<bourne7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> Thank you! Your post is really helpful.
>
> As mentioned above, I just want to understand how I would declare the 7
> REST routes if they would not have been declared for me, e.g. new1 (add in
> my example), edit1, ...
> If I declare add as a collection route, this statement throws an error
> <%= link_to ''Add Priority'', add_*priority*_path %>
(taken from
> originally created code :  <%= link_to ''New Priority'',
new_priority_path %>)
>
> <%= link_to ''Add Priority'', add_*priorities*_path
%> works as expected.
>
> My original question was: what is my definition missing compared to the
> original new?
>
>
> Second, I find this very interesting: get ''add'' =>
''priorities#create'', :as
> => my_custom_add
> In this form I get an error, the same with :my_custom_add.