I have been working on developing a blog site using rails. This is my
first rails application, hence I am fairly new to rails development.
Over the past week, I have encountered a few issues and hence I am
putting them all in one post here. Please feel free to comment on any
of the below mentioned issues:
- On my blog post I have my blog entries and their respective
comments. The visibility of the comments is toggled using a link. When
my blog page loads, the comments are being displayed by default.
However I want to hide the comments on page load and show them only
when the “Comments” link is clicked. I am using rjs to toggle the
visibility. Is there a way to hide the comments on page load? The code
that I have is shown below:
//Comments link: (blog.html.erb)
<%= link_to_remote pluralize(blogentry.comments.size, ‘Comment’), :url
=> { :action => ‘show_comments’, :entry => blogentry}%>
//RJS Templates : (show_comments.js.rjs)
entry = params[:entry]
page.visual_effect :toggle_blind, “Comment_box_#{entry}” , :duration
=> 0.5, :fps => 50
- I have also tried to categorize and archive the blog entries. For
that I am calling custom find methods. They are working fine and
everything is being done in the same method in the controller. Also I
have a single view file. However I would like to know if there is a
better way of doing this. Should I perform the find in separate
methods and have separate view files for each find (like separate view
for archives and categories)? Although I don’t think that would be a
DRY implementation. The code is shown below:
//page controller
def blog
@category = Category.find_by_name(params[:category_name])
if (params[:category_name])
@blogentries = Blogentry.find_all_by_category_id(@category.id)
elsif (params[:month] && params[:year] )
start = Time.mktime(params[:year], params[:month])
@blogentries = Blogentry.find(:all, :conditions => ['created_at
? and created_at < ?', start, start.next_month])
else
@blogentries = Blogentry.find(:all)
end
end
//blog.html.erb
<% for blogentry in @blogentries %>
//layout.html.erb (only the sidebar code with Archives and
Categories).
//This file provides the category, month and year required for
categorizing and archiving //respectively.
Any help here will be be greatly appreciated.
Thanks,
vishy