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 ......... partial code <%= render :partial => "comment", :object => message %> ......... show messages code (messages controller) def show @message = @article.messages.find(params[:id]) @message_comments = @message.comments respond_to do |format| format.html # show.html.erb format.xml { render :xml => @message } end end ........ post comment code (found in messages controller) def post_comment @message = @article.messages.find(params[:id]) @comment = Comment.new( "message_id" => @message.id, "created_at" => Time.now, "body" => params[:comment][''comment''], "author" => @current_user.first_name ) if @comment.save flash[:notice] = ''Comment was successfully added.'' redirect_to(article_messages_path(@article)) end end ......... _messages partial code <% form_tag :action => ''post_comment'' do %> <p><label for="comment_comment">Comment</label><br/> <%= text_field ''comment'', ''comment'' %> </p> <%= submit_tag "Post" %> <% end %> the page loads but when I click post to post the comment it does not put any data in the database and returns the following error...! ActiveRecord::RecordNotFound in MessagesController#post_comment Couldn''t find Article without an ID it seems to be coming from the before filter when the page is refreshed after posting. def get_article @article = Article.find(params[:article_id]) end used for the routes... can anyone help address this issue? -- 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-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 -~----------~----~----~----~------~----~------~--~---
On Thu, Jan 8, 2009 at 3:26 PM, Roger Muthton <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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/messagesCan you post the relevant routes you have? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Franz Strebel wrote:> On Thu, Jan 8, 2009 at 3:26 PM, Roger Muthton > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> 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 -- 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-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 -~----------~----~----~----~------~----~------~--~---
On Thu, Jan 8, 2009 at 4:16 PM, Roger Muthton <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> map.resources :articles do |articles| > articles.resources :messages > endand 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: http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial Good luck. Franz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > 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: > > http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial > > Good luck. > > FranzHi Franz, Thanks, ive got a comments controller being used now, along with a partial link, <% for message in @messages %> <%= render :partial => @comment = Comment.new, :locals => { :button_name => ''Post''}%> <% end %> this creates commments but without a message_id so I need to somehow pass the message_id to the partial so that it goes into the database. any ideas? -- 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-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 -~----------~----~----~----~------~----~------~--~---
Franz Strebel wrote:> On Thu, Jan 8, 2009 at 6:59 PM, Roger Muthton > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> <% 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 > > Franzhey 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. message has_many :comments comment belongs_to :message -- 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-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 -~----------~----~----~----~------~----~------~--~---
On Fri, Jan 9, 2009 at 3:37 PM, Roger Muthton <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> relationships are in my models already and it still is not putting the > id value in the database. > > message has_many :comments > comment belongs_to :messageCan you try this in your console? m = Message.find(:first) c = m.comments.new That should automatically set c.message_id to m.id to make the association. Franz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > Can you try this in your console? > > m = Message.find(:first) > c = m.comments.new > > That should automatically set c.message_id to m.id to make the > association. > > Franzyep that works spot on. -- 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-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 -~----------~----~----~----~------~----~------~--~---
On Fri, Jan 9, 2009 at 4:03 PM, Roger Muthton <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > >> >> Can you try this in your console? >> >> m = Message.find(:first) >> c = m.comments.new >> >> That should automatically set c.message_id to m.id to make the >> association. >> >> Franz > > yep that works spot on.OK, so the associations are in place. 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| -%> <!-- form body --> <% end -%> and of course if you nested Message under Article, it would be <% form_for([@message.article, @message, @comment]) do |f| -%> --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---