What I decided to do was to move .tagged_width to the model and reuse
the index with a slight tweak

in this manner:

# Posts_Controller
  def index
    #If the tags param is present, do by tags, if not, do all
    if params[:tags]
      @posts = Post.paginated_tag_search(params[:tags], params[:page])
      @tags = params[:tags]
    else
      @posts = Post.paginated_all(params[:page])
      @tags = nil
    end
  end

# Post_Model
  ## Find all with matching tags and paginate them
  def self.paginated_tag_search(search, page)
    options = {
      :order => 'created_at DESC',
      :page => page,
      :per_page => 25
    }
    Post.tagged_with(search, :include => [:tags, :user]).paginate
(options)
  end

  ## Find ALL And Paginate them
  def self.paginated_all(page)
    options = {
      :order => 'created_at DESC',
      :page => page,
      :per_page => 25
    }
    Post.find(:all, :include => [:tags, :user]).paginate(options)
  end

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to