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'' %>
<p>
<label for="comment_text">Comment</label><br/>
<%= text_area ''comment'', ''text'' %>
</p>
I think my question is very simple, hopefully I articulated it well
enough... Am I attacking this from the wrong direction?
~S
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---