ruby on rails 4 - Can't get over ActiveModel::ForbiddenAttributesError -
hello i'm trying learn rails , follow tutorial -> http://vimeo.com/10732081 explains how build blog page. use rails 4.1 , postscontroller is:
class postscontroller < applicationcontroller respond_to :html def index @posts = post.order("created_at desc") respond_with @posts end def create post.create(params[:post]) redirect_to posts_path end end
when create new post, using .erb page:
<h1>create new post</h1> <%= form_for post.new |form| %> <%= form.text_field :title %> <%= form.text_area :body %> <%= form.submit %> <% end %>
it throws activemodel::forbiddenattributeserror
after googling (including pages stackoverflow) found addition of like
params.permit post: [:title, :body]
was necessary, it's uncertain put method , parameters should used. looks of answers suppose know ruby , rails don't, i'm newbie. need help, thanks.
try this:
# app/controllers/posts_controller.rb def create post.create(post_params) redirect_to posts_path end private def post_params params.require(:post).permit(:title, :body) end
Comments
Post a Comment