0

I just implement acts-as-taggable-on on my blog model. Working great.

The visitor can filter blogpost based on the tag. So on my index blog there is a tagcloud with a bunch of tags (links). The url is domain.com/tag/greatbars ect

Question: How can i place some unique content on top of my index based on the filtered tag?

example: blogpost are filter by "greatbars" h1: The posts are filter by "tagname" h2: Below you see some great bars in the region of amsterdam. Check it out. p: ect ect

Blog listing based on filtered tag(s)

user229044
  • 232,980
  • 40
  • 330
  • 338
Remco
  • 681
  • 1
  • 6
  • 20

1 Answers1

1

The action which renders the index presumably takes the filtered tag as a parameter. You can save that tag as an instance variable, and then in the index view display certain content if that variable has a particular value. Basic example:

Controller

  def index
    @tag = Tag.find_by_name(params[:tag])
    @posts = Post.tagged_with(@tag)
  end

View

  <% case @tag.name %>
  <% when 'bars' %>
    <%= render :partial => 'posts/bars')
  <% when 'foos' %>
    <%= render :partial => 'posts/foo_stuff')
  # as many other cases as you wish
  <% else %>
    <%= render :partial => 'posts/default')
  <% end %>
# rest of existing index view
MrTheWalrus
  • 9,670
  • 2
  • 42
  • 66