Link_to frustration...help?

I have a resource 'users'. the index page has a 'link_to' tag I created on the line item level for a specific view. The link_to that is frustrating me in particular says: <%= link_to 'View', :controller => 'users', :action => 'view' %>

What's happening is that it's going to the Users controller and attempting to execute the 'show' action (with 'view' passed in as the id). But i am specifically requesting it to use the link_to to go to the 'view' action. I've tried routing to another controller as well and that doesn't change it at all.

This is a rails 2.3.8 app if that matters in evaluating my question/ problem. Any help would be really appreciated. As an aside, I've even tried hi-jacking the 'show' action by looking for a params id = 'view' and it fails before it even gets there (so assuming the route is smart enough to expect a non-string value).

Phil

I have a resource ‘users’. the index page has a ‘link_to’ tag I

created on the line item level for a specific view. The link_to that

is frustrating me in particular says: <%= link_to ‘View’, :controller

=> ‘users’, :action => ‘view’ %>

What’s happening is that it’s going to the Users controller and

attempting to execute the ‘show’ action (with ‘view’ passed in as the

id). But i am specifically requesting it to use the link_to to go to

the ‘view’ action. I’ve tried routing to another controller as well

and that doesn’t change it at all.

It will be a lot easier to just use the name of the route, eg, =link_to “View”, view_user_path(user) (or whatever the name of the route is; you can always find it in the output of rake routes.

In this case the view I want to render is not one of the routes. I already have a show/edit/index view, I now need another one that is specialized and this may not be the last one I need.

In this case the view I want to render is not one of the routes. I

already have a show/edit/index view, I now need another one that is

specialized and this may not be the last one I need.

If you want to link_to the way you’re doing, it will need to be a route; you can add routes other than the standard RESTful set. See the routing guide in guides.rubyonrails.org.

Yes, you could one off 'render :template => “view” if params[:id] == “view” ', (or something like this, in the show action) but I really would discourage this sort of thing; your controller will become very hard to maintain.

Phil

Got it. Understand the points on not using the render in the show action. Thanks for the help, I appreciate it.

In this case the view I want to render is not one of the routes. I already have a show/edit/index view, I now need another one that is specialized and this may not be the last one I need.

Then add a route. ( check the :member option to resources)

Fred

The best way would be to create named route however you can probably use url_for() for the job. You need to have globa routing turned on to make it working:

link_to 'View', url_for(:controller => 'users', :action => 'view')

Robert Pankowecki