Ruby on Rails Tuesday, September 2, 2014

If you change it to @comment.save! does the response work equally as well or do you get an error.

Try putting a debugger (see pry for Ruby < 2 or byebug for Ruby 2) line on the line before @comment.save, run the code (actually run the test!) and on the debugger line type "@comment.save" and see what it says.


On Aug 30, 2014, at 8:40 PM, Mohammed Rashid <lists@ruby-forum.com> wrote:

> I am trying to create my first ever program Using Ruby programming
> language on Ruby on Rails and it is a blog! I am following a tutorial
> and have created a comments box which does NOT print the comment on the
> page so far when written in the comments box, that's the problem. I will
> explain step by step I have:
>
> 1. Called out on routes.rb:
>
> resources :posts do
> resources :comments
> end
>
> 2. Called out using Cmder:
> rails g controller comments create destroy
>
>
> 3. This is my comments_controller.rb class:
>
> class CommentsController < ApplicationController
> def create
> @post = Post.find(params[:post_id])
> @comment = @post.comments.build(params[:comment]) #around here is
> the error
> @comment.save
>
> redirect_to @post
> end
>
> def destroy
> end
> end
>
>
>
> can anybody please help?
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/335bf9a03da77a47707ee83e516d92d4%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/16959D8F-AAAA-4857-8734-1E4D6D225FE1%40datatravels.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment