Hello, I''m following the tutorial at http://guides.rubyonrails.org/getting_started.html. I got to the point where adding new posts should be functional (the end of 5.7). When I try to submit a post, I receive the error stating "Can''t convert Symbol into String". The trace shows: app/controllers/posts_controller.rb:16:in `post_params'' app/controllers/posts_controller.rb:6:in `create'' This error occurred while loading the following files: post The code in my posts_controller.rb file is: class PostsController < ApplicationController def new end def create @post = Post.new(params[:post].permit(:title, :text)) @post.save redirect_to @post end def show @post = Post.find(params[:id]) end private def post_params params.require(:post).permit(:title, :text) end end ___ Can anyone give me any pointers on why this might be happening? Or is there any other portion of the application what would be helpful to see for troubleshooting? Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/02e92a8e-3f29-4386-a87f-e750bac3abb1%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Saturday, July 6, 2013 10:34:53 PM UTC+1, Josh Swasey wrote:> > Hello, > > I''m following the tutorial at > http://guides.rubyonrails.org/getting_started.html. I got to the point > where adding new posts should be functional (the end of 5.7). When I try to > submit a post, I receive the error stating "Can''t convert Symbol into > String". The trace shows: > > >This looks like your code is expecting strong_parameters to be setup (available as a gem in rails 3.2, turned on by default in 4.0) but your app isn''t using strong parameters. Which version of rails are you using ? Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0c7c7dc6-fea5-48c6-97f2-c741bf541364%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
change @post = Post.new(params[:post].permit(:title, :text)) to @post = Post.new(post_params). you only need use Post.new([methods]) [methods] => define on private methods thats is your strong parameter works.. Pada Minggu, 07 Juli 2013 4:34:53 UTC+7, Josh Swasey menulis:> > Hello, > > I''m following the tutorial at > http://guides.rubyonrails.org/getting_started.html. I got to the point > where adding new posts should be functional (the end of 5.7). When I try to > submit a post, I receive the error stating "Can''t convert Symbol into > String". The trace shows: > > app/controllers/posts_controller.rb:16:in `post_params'' > app/controllers/posts_controller.rb:6:in `create'' > > This error occurred while loading the following files: > post > > > The code in my posts_controller.rb file is: > class PostsController < ApplicationController > def new > end > def create > @post = Post.new(params[:post].permit(:title, :text)) > > @post.save > redirect_to @post > end > def show > @post = Post.find(params[:id]) > end > private > def post_params > params.require(:post).permit(:title, :text) > end > end > > ___ > Can anyone give me any pointers on why this might be happening? Or is > there any other portion of the application what would be helpful to see for > troubleshooting? > > Thanks. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7d088791-ec0d-455e-a796-3f51f5115c49%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.