3

I am using Ruby on Rails 3.0.9 and I had this problem: Trouble on setting the ':controller' parameter for a 'link_to' statement. No one answered with a solution but, trying and re-trying to find and solve the problem, I have found that on passing "old style" parameters (that is, using controller and action options instead of named route paths) sometime a link_to doesn't work as expected (that is, you get a ActionView::Template::Error - No route matches error although if you have controller and routes properly stated). Anyway you can set for that something like the following:

<%= link_to("New article", {:controller => '../', :action => 'new'}) %> # Note the "'../'"

and it works.

I would like to know when and why, in general, it happens: the controller option seems "forced" to refer to the relative or absolute path and not to the controller parameter you passed in.

That is, if I set :controller => articles and I use the above code in a view file managed by the controllers/article/categories_controller.rb I get the following error:

`ActionView::Template::Error (No route matches {:controller=>"articles/categories/articles", :action=>"new"})`

because, as said above, the controller seems to refer to the /articles/categories path instead of /articles path (as it should be since, in this example, I set the controller to articles). Can be it a router problem?

Community
  • 1
  • 1
Backo
  • 18,291
  • 27
  • 103
  • 170

1 Answers1

1

The "no route error " generally occurs when there is no proper route mentioned in routes.rb file.It has nothing to do with the absolute/relative path.

louiscoquio
  • 10,638
  • 3
  • 33
  • 51
ramya
  • 928
  • 5
  • 14
  • 30