Ok, my site is setup like pretty much every other blog out there. A
list of the most recent 5 posts, then by clicking one, you go to an
individual post page, displaying the full context of that post.
Now, what I would like to do is to display the related entries in the
side column, which is part of the layout, based on the tags belonging to
that specific entry.
Here’s my coding so far:
#view
<% for post in @posts %>
<%= post.title %>
tags: <%= post.tags.collect { |tag| link_to tag.name, :controller =>
“articles”, :action => “by_category”, :category => tag.name.to_s
}.join(", ") %>
<%= post.entry %>
<% end %>
#layout
<% for related in @contents_related %>
#controller (how do I pass the tag_id and the content_id?)
@contents_related = Content.show_related_entries(?,?)
#model
def self.show_related_entries(t_id, c_id)
find_by_sql(“select c.title from contents c inner join contents_tags
ct on c.id = ct.content_id where ct.tag_id = #{t_id} and c.id !=
#{c_id}”)
end
The function works if I manually pass a content_id (for my entry) and a
tag id (for a tag of that entry). Now, how can I dynamically pull out
the single content_id for the post, but execute the function for each
tag related to that individual post???
Hopefully you can see what I’m trying to accomplish, and can have a
suggestion (even if it’s completely different) as to how I can get this
working!
Thanks for any help!