sent-hil
sent-hil

Reputation: 19305

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

Upvotes: 0

Views: 418

Answers (2)

Mark Locklear
Mark Locklear

Reputation: 5335

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

Upvotes: 0

Jimmy Baker
Jimmy Baker

Reputation: 3255

Modify your controller code so that it reads something like:

@posts = Post.tagged_with(params[:tag], :on => 'tags')

Upvotes: 1

Related Questions