Forgive my ignorance but I am brand new not only to Ruby but programming in general. I am working through the example on edge guides at rubyonrails.org. and am receiving the following error and despite reviewing every piece of code I've typed since the app last worked I am unable to fix it.
NoMethodError in PostsController#create
undefined method `permit' for {"title"=>"", "text"=>""}:ActiveSupport::HashWithIndifferentAccess
And this is what my posts_controller.rb looks like:
class PostsController < ApplicationController
def new
@post = Post.new
end
def create
@post = Post.new(params[:post].permit(:title, :text))
if @post.save
redirect_to action: :show, id: @post.id
else
render 'new'
end
end
def show
@post = Post.find{params[:id]}
end
def index
@posts = Post.all
end
end
What am I doing wrong?
Thank you in advance for any help!
params
you get in a controller action is an instance of theActiveSupport::HashWithIndifferentAccess
class, andpermit
is not an instance method for that class, so this definitely won't work. What are you actually trying to achieve? – Iselaisenberg