B
B
bobanuk2015-02-13 13:44:48
Ruby on Rails
bobanuk, 2015-02-13 13:44:48

Can the acts-as-taggable-on gem bring the last 10 entries from the tag to the main page?

Hello, help me figure it out. There is a Film model, you need to display 3 tapes of the last 10 records in index.htm.erb from the show mult film tags using the acts-as-taggable-on gem.

films_controller.rb
  def index
    if params[:tag].present?
      @films = Film.tagged_with(params[:tag]).paginate(:page => params[:page], :per_page => 10)
    else
      @films = Film.all.order("created_at DESC").paginate(:page => params[:page], :per_page => 10)
    end
  end

index.html.erb
      <td><% film.tags.any? %>
        <% film.tags.each do |tag| %>
    <span class="label label-teal">
        <%= link_to tag.name, tag_path(tag.name) %>
     </span>
        <% end %></td>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ilyasov, 2015-02-13
@bobanuk

Try this, unfortunately I can't try it right now.
@last_show_films = Film.tagged_with("show").order("created_at DESC").limit(10)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question