To find by tag
To find by tag:
Modify list method
def list
# new to help find by tags
@tag = @params['tag']
# original before search
@sites = Site.find_all
end
and edit list.rhtml in views/site directory
<% @sites.each do |site| %>
<% if (@tag == nil) || (@tag == site.tag.tag)%>
and add
<%= link_to site.tag.tag,
:action => "list",
:tag => "#{site.tag.tag}" %>
Note that because of
:tag => "#{site.tag.tag}"
the following gets added to the URL
http://socialbookmarking.org/site/list?tag=encyclopaedia
1 Comments:
I find that an easy way is to do a tag search with MySQL. This can be achieved by having a 'tag' column in your database table, and then storing the tags between < and > delimeters. I.e., if a page is tagged as separated by spaces, then the value in the tag column would be < separated by spaces >. That way, you could do in Rails something like @tag_results = Table.find ( :first, :conditions => [ " tags LIKE ? ", "% "+params[:tag_to_list] +" %" ] )
That's just something I came up with - it's probably not perfect as I'm a relative newcomer to MySQL/Rails.
Post a Comment
<< Home