开发者

Acts_as_taggable_on link_to

开发者 https://www.devze.com 2022-12-16 05:51 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消