# Member variable in controller

**URL:** <https://www.ruby-forum.com/t/member-variable-in-controller/113043>\
**Category:** Rails\
**Created:** [August 26, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/member-variable-in-controller/113043 "2007-08-26T19:44:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [August 26, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/member-variable-in-controller/113043/1 "2007-08-26T19:44:21Z")

</div>

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
