Member variable in controller

I have a news_controller. The ‘show’ action shows an article, and at
the bottom of the page there is a form to submit a new comment. The
show method sets @article member variable to the article about to be
shown.

def show
@article = Article.find(params[:id])
end

When the addcomment action is called, when the submit clicked. I need
to know the id of the article in the addcomment method.

def comment
comment = Comment.new
comment.article = @article #this does not work
comment.text = params[:comment][:text]
comment.created = DateTime.now
if comment.save
flash[:notice] = ‘Comment was successfully added.’
end
redirect_to :action => ‘show’
end

My form looks like this:
<% form_tag :action => ‘comment’ do %>
<%= render :partial => ‘commentform’ %>
<%= submit_tag “Submit” %>
<% end %>

and _commentform.rhtml is
<%= error_messages_for ‘comment’ %>

Comment
<%= text_area 'comment', 'text' %>

I think my question is very simple, hopefully I articulated it well
enough… Am I attacking this from the wrong direction?

~S

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs