3

My app I am building uses, Activeadmin for a back-end interface.

I currently use this for easy production for my clients to add simple things into the back-end like products etc.

I have set up using rails 4 and the activeadmin rails 4 compatible version.

When I go to add a new band in the back-end I get this error:

ActiveModel::ForbiddenAttributesError in Admin::BandsController#create
ActiveModel::ForbiddenAttributesError

Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"YnzHk2juyZ6W2kVS5ZVPCimoj7LSHRI1Oen4BHjaqfc=",
 "bands"=>{"title"=>"Kings of Leon",
 "picture"=>"blank"},
 "commit"=>"Create Bands"}

I know that this is to do with the creation of a new item in the backend but I am unsure where to start from fixing this bug.

Any help would be great,

Thanks

M dunbavan
  • 1,157
  • 5
  • 22
  • 57
  • 2
    Take a look there http://stackoverflow.com/questions/13091011/how-to-get-activeadmin-to-work-with-strong-parameters – yannick Jul 23 '13 at 17:57

2 Answers2

10

Just add the following line to your app/admin/brand.rb

permit_params :title, :picture

and then restart your server.

suffering
  • 225
  • 3
  • 8
  • It should be noted that after install ActiveAdmin, Inherited Resources gem will take over the creation of controllers for any command-line scaffolding. If running Rails 4 or the Strong Parameters gem, one will need to add permitted_params to those controllers, as well. Cite: https://github.com/josevalim/inherited_resources#strong-parameters – scarver2 Dec 29 '13 at 15:08
3

I've just met that error and I've found the way to fix it already.

Solution: clarify permit syntax for params in controller, this is new in Rails 4 and very easy to make mistakes.

For example, these code will take the error (apply permit to the params then use the origin params):

params.require(:seller).permit(:company, :phone)
@seller.update_attributes(params[seller])

To fix it, replace them with:

@seller.update_attributes(params.require(:seller).permit(:company, :phone))

... or reuse the permitted params (recommended solution):

new_attributes = params.require(:seller).permit(:company, :phone)
@seller.update_attributes(new_attributes)

Hope it could help you.

Hoang Le
  • 1,341
  • 14
  • 14