# 2 Issues - On load component hiding ; Separate find methods

**URL:** <https://www.ruby-forum.com/t/2-issues-on-load-component-hiding-separate-find-methods/162296>\
**Category:** Rails\
**Created:** [March 8, 2009, 7:00am UTC](https://www.ruby-forum.com/t/2-issues-on-load-component-hiding-separate-find-methods/162296 "2009-03-08T07:00:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@vishy](https://www.ruby-forum.com/u/vishy)\
**Post date:** [March 8, 2009, 7:00am UTC](https://www.ruby-forum.com/t/2-issues-on-load-component-hiding-separate-find-methods/162296/1 "2009-03-08T07:00:46Z")

</div>

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:

1. 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

1. 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](https://blog.html.erb)  
\<% for blogentry in @blogentries %\>

 \<%= h blogentry.title %\> 

 \<%=h blogentry.body %\> 

\<% end %\>

[//layout.html.erb](https://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.

 CATEGORIES 
 \<% for category in @categories%\> \<% @entry = Blogentry.findforCatergoryid(category.id) %\> \<%= link\_to category.name.upcase + "(#{@entry.length})", category\_entries\_path(category.name)%\> \<% end%\> 

 ARCHIVES 
 \<% @entries\_by\_month.each do |month, entry|%\> \<%= link\_to month.strftime('%B %Y').upcase, archive\_path (month.strftime('%Y'), month.strftime('%m'))%\> \<% end%\> 

Any help here will be be greatly appreciated.

Thanks,  
vishy

---

<div class="post-metadata">

**Author:** ![vishy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@vishy](https://www.ruby-forum.com/u/vishy)\
**Post date:** [March 9, 2009, 2:31am UTC](https://www.ruby-forum.com/t/2-issues-on-load-component-hiding-separate-find-methods/162296/2 "2009-03-09T02:31:51Z")

</div>

to answer your first question, hiding the comments by default is easy.  
simply add a “display:none” to the CSS for the divs you wish to be  
hidden initially.
