Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostsController Update Method Not Working #17

Closed
helloamandamurphy opened this issue May 6, 2019 · 0 comments
Closed

PostsController Update Method Not Working #17

helloamandamurphy opened this issue May 6, 2019 · 0 comments

Comments

@helloamandamurphy
Copy link

Current code:

def update
	  @post = Post.find(params[:id])
	  @post.update(params.require(:post))
	  redirect_to post_path(@post)
	end

It gives me this error:

 1) form shows an update form that submits content and redirects and prints out params
     Failure/Error: @post.update(params.require(:post))
     
     ActiveModel::ForbiddenAttributesError:
       ActiveModel::ForbiddenAttributesError

What worked for me:

	def update
	  @post = Post.find(params[:id])
	  @post.update(params.require(:post).permit!)
	  redirect_to post_path(@post)
	end

I also don't understand why the routes aren't written in this ReadMe. If it's a ReadMe and it's not teaching routes, they should be written so we can focus on the material being taught. It's distracting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant