Restful controllers - howto nest with link_to?

Hi List,

I’m trying to get my grip on the restful methods that are now part of
edge
rails.

Making the first steps was impressive as well as easy because there are
already great resources on the blogs of early adopters:
http://www.ryandaigle.com/articles/2006/08/01/whats-new-in-edge-rails-simply-restful-support-and-how-to-use-itand
http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared for
example.

Following these tutorials it’s a piece of cake to setup the first
restful
controllers and even get nested routes like
/users/1/projects/3 to work. I really like these ‘talking’ urls, list
project ‘3’ of user ‘1’ and so something with it by using the http-verbs
put, delete, post and get.

What I don’t get yet is how to create something like a link to
/users/1/projects/3;edit with the view helpers. One could of course say
that
I might directly link_to :controller => ‘projects’, :action => ‘edit’,
:user_id => user but I want to link to the full rest-url because of
readility reasons.

Something like <%= link_to ‘Add Project’, :controller => ‘users’,
:action =>
“#{user.id}/projects/new” %> does what I want from a technical
perspective,
but results in an encoded url (
http://localhost:3002/users/1%2Fprojects%2Fnew ) which doesn’t look as
elegant as the whole approach… There’s got to be a railish way to
construct this url unencoded. I just don’t get it. Could someone please
give
me the insights. I’m already addicted to this new form of urls…

Cheers,
Jan

Hi Josh,

great, thanks. I’ll definitly try these out.

Cheers,
Jan

Jan P. wrote:

Following these tutorials it’s a piece of cake to setup the first
restful controllers and even get nested routes like
/users/1/projects/3 to work. I really like these ‘talking’ urls, list
project ‘3’ of user ‘1’ and so something with it by using the http-verbs
put, delete, post and get.

What I don’t get yet is how to create something like a link to
/users/1/projects/3;edit with the view helpers. One could of course say
that
I might directly link_to :controller => ‘projects’, :action => ‘edit’,
:user_id => user but I want to link to the full rest-url because of
readility reasons.

Something like <%= link_to ‘Add Project’, :controller => ‘users’,
:action =>
“#{user.id}/projects/new” %> does what I want from a technical
perspective,
but results in an encoded url (
http://localhost:3002/users/1%2Fprojects%2Fnew ) which doesn’t look as
elegant as the whole approach… There’s got to be a railish way to
construct this url unencoded. I just don’t get it. Could someone please
give me the insights. I’m already addicted to this new form of urls…

Use the _url or _path helper for the route you want.

<%= link to h(@project.name), edit_project_path(@user, @project) %>
<%= link_to “delete”, project_path(@user, @project),
:method => :delete, :confirm => “Are you sure?” %>
For non-GET verbs, you’ll need to include the method as an option, and a
JS confirmation if you like that sort of thing.


Josh S.
http://blog.hasmanythrough.com