Forum: Ruby on Rails 2 Issues - On load component hiding ; Separate find methods

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4ee5ca38cb149788ca612902d857212e?d=identicon&s=25 vishy (Guest)
on 2009-03-08 07:00
(Received via mailing list)
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

2) 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 %>
<div id="blog_entry">
  <div id="blog_heading">
    <%= h blogentry.title %>
  </div>
  <div id="blog_content">
    <%=h blogentry.body %>
  </div>
</div>
<% end %>

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

<div id="sidebar">
  <div class = "side_content">
  <div> CATEGORIES </div>
  <% for category in @categories%>
    <% @entry = Blogentry.findforCatergoryid(category.id) %>
    <%= link_to category.name.upcase + "(#{@entry.length})",
category_entries_path(category.name)%>
    <% end%>
  </div>
  <div class = "side_content">
  <div> ARCHIVES </div>
  <% @entries_by_month.each do |month, entry|%>
    <%= link_to month.strftime('%B %Y').upcase,         archive_path
(month.strftime('%Y'), month.strftime('%m'))%>
  <% end%>
  </div>
</div>

Any help here will be be greatly appreciated.

Thanks,
vishy
6fabb84e727dee98d1277df56458cbac?d=identicon&s=25 Andrew Bloom (Guest)
on 2009-03-09 02:31
(Received via mailing list)
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.
This topic is locked and can not be replied to.