RubyonRails_newbie wrote:
>  def comment
>      @blogcomment = Blogcomment.find(:all, :order => "created_at
> desc")

I don't understand the point to this. See next comment...

>       @user = User.find(session[:user_id])

Nor this...

> 
>      Blogpost.find(params[:id]).blogcomments.create(params[:comment])
>         flash[:notice] = "Added your comment"
>         redirect_to :action => "show", :id => params[:id]

Here you are unconditionally redirecting to :action => "show" so what's 
the point of the above fetch of Blogcomment?

>   end

By the way, this method is trying to do too much.

- It's fetching an array of Blogcomments (that it doesn't seem to do 
anything with)
- It finds a user (and doesn't seem to use it either)
- It finds a Blogpost and creates a new Blogcomment on it.
- It sets flash[:notice]
- And finally redirects to the "show" action

The only effective thing it does should be handled by the Blogcomment's 
"create" method anyway.
At least in the modern RESTful Rails world. You have written a custom 
method for something that can be easily handled by the basic CRUD 
actions of RESTful controllers.

The redirect_to will create a new request/response cycle causing all 
instance variables set in this method to be freed for garbage 
collection.
-- 
Posted via http://www.ruby-forum.com/.

-- 
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-t...@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