I use active-record 4.0 in a grape api application, but as strong parameter only works in rails controller, how do I permit params in a grape api class
Asked
Active
Viewed 1,057 times
1 Answers
8
There seems to be a way to use the strong parameters outside the controller
raw_parameters = { :email => "john@example.com", :name => "John", :admin => true }
parameters = ActionController::Parameters.new(raw_parameters)
user = User.create(parameters.permit(:name, :email))
For more info check the repository documentation on github https://github.com/rails/strong_parameters
Regards

Calin
- 6,661
- 7
- 49
- 80
-
1it is working for creating a new record but not working for update. Can you please help me in updating the record? Thanks in advance. – Mohd Anas Mar 01 '17 at 07:10
-
The same pattern should apply, only use `.update_attributes(parameters.permit(:name, :email)` instead of create. – Calin Mar 01 '17 at 13:50