0

I have a view with the following link generator:

- @tags.each do |tag|
  = link_to tag.name, :controller => "images", :action => "#{tag.name}"

@tags is Tag.all. It displays the links with the correct names, mouseover shows e.g.

http://localhost:3000/Images/tagname

but if I click on one the error is:

No route matches {:controller=>"", :action=>""}

How can it say :controller is empty when I specified :controller => "images"?

rake routes (relevant part):

images GET           /images(.:format)                     images#index
POST                 /images(.:format)                     images#create
new_image GET        /images/new(.:format)                 images#new
edit_image GET       /images/:id/edit(.:format)            images#edit
image GET            /images/:id(.:format)                 images#show
PUT                  /images/:id(.:format)                 images#update
DELETE               /images/:id(.:format)                 images#destroy
tags GET             /Images(.:format)                     tags#index
POST                 /Images(.:format)                     tags#create
new_tag GET          /Images/new(.:format)                 tags#new
edit_tag GET         /Images/:id/edit(.:format)            tags#edit
tag GET              /Images/:id(.:format)                 tags#show
PUT                  /Images/:id(.:format)                 tags#update
DELETE               /Images/:id(.:format)                 tags#destroy

One tag e.g. is "saturn", so I added this route too in routes.rb:

match '/Images/saturn'                => 'images#saturn'

which leads to:

Images_saturn        /Images/saturn(.:format)              images#saturn

I also have a method "saturn" in my images controller.

ksugiarto
  • 940
  • 1
  • 17
  • 40
user929062
  • 807
  • 4
  • 12
  • 33
  • 1
    can you post the result of `rake routes` here? – Erez Rabih Sep 27 '12 at 13:59
  • 1
    more stack trace? quite possibly it's the view that you're linking *to* which contains the bad url helper method, not the view with these tag links. after all, if you had a routing error in this view, you'd get the error when you tried to load it, not when you tried to leave it. – gregates Sep 27 '12 at 14:11
  • I have added the rake routes results. – user929062 Sep 27 '12 at 14:23

3 Answers3

0

Try

= link_to tag.name, {:controller => "images", :action => "#{tag.name)}"}

Rubyman
  • 874
  • 6
  • 15
0

You have an extra ")" after

"#{tag.name)}"
monangik
  • 366
  • 1
  • 9
0

Looks to me like you have a capitalization issue. You have in your routes both /images and /Images ... Can you try fixing that?

likethesky
  • 846
  • 3
  • 12
  • 28