Question

I am trying to learn the new changes in rails 4 so started with a blog . Ran a scaffold with a title and body , everything went well until i clicked on save and i was greeted with the error ActiveModel::ForbiddenAttributesError . I know i need to make some changes in controller , but i read the blogs and made changes for the same .

Following is my controller

class BlogpostsController < InheritedResources::Base
  def create
     Blogpost.create(blogpost_params)
  end

  private
  def blogpost_params
    params.require(:blogpost).permit(:body,:title)
  end
end

Please do point me the right way as i am still new to rails 4 and also any tutorials defining the same would also be helpful . Thanks in advance :)

Was it helpful?

Solution

You have controller code in a model class , that's what wrong. The create action and the strong parameters should be defined in your blog_posts controller. The code itself seems fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top