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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -