I have a model Image:
class Image < ActiveRecord::Base
attr_accessible :description, :name, :size, :image, :tag_ids
has_many :taggings, :dependent => :destroy
has_many :tags, :through => :taggings
end
Then I have my Tag model:
class Tag < ActiveRecord::Base
attr_accessible :name
has_many :taggings, :dependent => :destroy
has_many :images, :through => :taggings
end
My routes.rb is currently:
resources :images do
get 'confirm_destroy', :on => :member
end
resources :tags
Now let's say I created a few tags "blue", "red" and "yellow" for the images. On some page I want to show a list of tags and then link them to e.g. www.example.com/yellow where all the images tagged as yellow shall be shown. The view (haml) for this tag list is currently:
- @tags.each do |tag|
= link_to(tag.name, tag)
But it generates a link to www.example.com/tags/2 (with 2 being the tag_id).
How can I create the correct resources in order to link to www.example.com/yellow instead of www.example.com/tags/2. Will the view with "link_to" be the same in this case?