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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to