Acts_as_taggable_on link_to
I installed the Acts as taggable on plugin to my 'Post' model, however I'm unable to call up a list of posts tagged with certain tag.
Here's what I have in show.
<%= link_to tag.name, posts_path(:view =>'tag', :tag => tag.name) %><% end %>
Except when I click on it, it shows all posts. I want it to show just the posts tagged with that 开发者_运维问答keyword...what am I doing wrong here?
Thanks for your help
Modify your controller code so that it reads something like:
@posts = Post.tagged_with(params[:tag], :on => 'tags')
Here is what I ended up doing...
index view
<% job.tags.each do |tag| %>
<div class="tag"><%= link_to(tag, jobs_path(tag: tag.name), method: :get) %></div>
<% end %>
index action in the controller
if params[:tag]
@search_term = params[:tag]
@jobs = Job.tagged_with(@search_term)
end
精彩评论