Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Patrick Crowley
RE: Browse newest added? [ reply ]  
2006-09-30 01:07
Sorry, guys -- I just stupidly realized that I'm using the acts_as_taggable plugin, not the gem.

So, to maintain sanity, please ignore this whole thread.

By: Greg Newman
RE: Browse newest added? [ reply ]  
2006-09-26 21:43
No problem Patrick. Give a link to the blog post when it's up. :)

By: Patrick Crowley
RE: Browse newest added? [ reply ]  
2006-09-26 21:36
Ok, I've got this working!!! Thanks for your help, Greg.

To make del.icio.us style tag views possible, I had to basically rewrite the tag_with method in acts_as_taggable.rb and also extend the find_tagged_with method to order results by taggable.id DESC.

When I get a chance, I'll write a blog post with the final code.

By: Patrick Crowley
RE: Browse newest added? [ reply ]  
2006-09-26 02:42
Yeah, it does work, but isn't quite as accurate as I would like.

If I tag a post 'apple' and 'itunes', the post appears on the top of those pages.

But, if days later, I come along and I add a new tag to this same post -- let's say I add the tag 'music' -- the post will appear on the top of the 'music' tag page.

However, it will also move to the top on the 'apple' and 'itunes' tag pages, even though I've already used these tags.

...

So the trick would be to find a way to sort the posts based on taggings.id (since newer tags will have higher ids).

By: Greg Newman
RE: Browse newest added? [ reply ]  
2006-09-26 02:36
Yes, add it to the posts table. In my feeble-sleep-deprived mind it should work.

By: Patrick Crowley
RE: Browse newest added? [ reply ]  
2006-09-26 02:34
You mean add updated_at to the Post table, right?

That would work -- but if I add a new tag to a Post that already has tags, it would float to the top of all tag listings where it appears.

Ideally, I want to sort posts by the date each tag is added to the taggings tale.

By: Greg Newman
RE: Browse newest added? [ reply ]  
2006-09-26 02:03
Ok. You can also add a updated_at field as a datetime and sort by that. Then it would pull the latest updated field. I would do both the created_at and updated_at since they are both automagically populated with rails. Then pull your order by accordingly.

By: Patrick Crowley
RE: Browse newest added? [ reply ]  
2006-09-26 01:57
I'll try that.

Right now, I have a rough approximation. I'm sorting by post.id DESC so newest posts will appear at the top of the list for each tag... but, if i tag an older post, it won't appear at the top of the list (since the post.id is older).

So, I really need to be sorting on taggings.id DESC or perhaps the created_at field you suggested.

Here's the code I'm using to load the posts for a specific tag.

@tag_pages, @posts = paginate(Post, {:conditions => ['tags.name = ?', @tag], :include => [:tags], :per_page => 10, :order => 'posts.id DESC'})

By: Greg Newman
RE: Browse newest added? [ reply ]  
2006-09-26 01:50
Try adding a field to your table for created_at and then add that field as a order by

By: Patrick Crowley
Browse newest added? [ reply ]  
2006-09-26 01:46
Is there a way to browse tagged content by the newest item added?

I'd like to do something like del.icio.us where newly tagged links appear on the first page of results for a tag.