Hey folks, first timer here so be gentle. I have a messages page which
uses a partial to display comments for each message for an article and a
little box under each message so people can comment on that message.
located at http://localhost:3000/articles/6/messages
Hey folks, first timer here so be gentle. I have a messages page which
uses a partial to display comments for each message for an article and a
little box under each message so people can comment on that message.
located at http://localhost:3000/articles/6/messages
Hey folks, first timer here so be gentle. I have a messages page which
uses a partial to display comments for each message for an article and a
little box under each message so people can comment on that message.
located at http://localhost:3000/articles/6/messages
Can you post the relevant routes you have?
map.resources :articles do |articles|
articles.resources :messages
end
map.resources :articles do |articles|
articles.resources :messages
end
and comments belong_to :messages right? if so, add it in the routes
map.resources :articles do |articles|
articles.resources :messages do |messages|
messages.resources :comments
end
end
It is better practice to have a CommentsController to operate on your
comments instead
of using the Messages controller. I highly suggest that you then use
this tutorial as your
starting point to move forward:
It is better practice to have a CommentsController to operate on your
comments instead
of using the Messages controller. I highly suggest that you then use
this tutorial as your
starting point to move forward:
<% for message in @messages %>
<%= render :partial => @comment = Comment.new, :locals => { :button_name
=> ‘Post’}%>
<% end %>
If you have your association setup properly between Message and Comment
models,
then you can do
@comment = message.comments.new
Franz
hey franz, sorry to be a pain, but I have tried that, and the
relationships are in my models already and it still is not putting the
id value in the database.
Can you show the form you use for creating/editing comments? Assuming
that in your
CommentsController, you have a before_filter to get the @message à la:
@message = Message.find(params[:message_id])
and in your new method: @comment = @message.comments.new
while in your edit method: @comment = @message.comments.find(params[:id])
You have to make sure that in your form, you do
<% form_for([@message, @comment]) do |f| -%>
<% end -%>
and of course if you nested Message under Article, it would be
<% form_for([@message.article, @message, @comment]) do |f| -%>
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.