Skip to content

Instantly share code, notes, and snippets.

@wfarr
Created August 30, 2009 17:57
Show Gist options
  • Select an option

  • Save wfarr/178058 to your computer and use it in GitHub Desktop.

Select an option

Save wfarr/178058 to your computer and use it in GitHub Desktop.
def tag
@tag = params[:tag]
- if @tag =~ /,/
- @posts = []
- @tag.split(",").each do |tag|
- @posts << Post.find(:all, :conditions => ["tags LIKE ?", "%#{tag}%"] ).map {|p| p.id }
- end
- @posts = @posts.flatten.uniq.sort.reverse
- @posts.map! {|post| Post.find(post) }
- else
- @posts = Post.find(:all, :conditions => [ "tags LIKE ?", "%#{@tag}%"] ).reverse
- end
+ @tag = @tag.split(",") if @tag =~ /,/
+ @posts = Post.all(:conditions => { :tags => @tag }, :order => 'created_at desc' )
respond_to do |format|
format.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment