Closed boy-jer closed 11 years ago
Hey I use it constantly with strong_params
. The whole idea of strong_params
was to put that stuff in the controller an not on the model.
So here is what it should look like:
class User
include Virtus
include ActiveModel::ForbiddenAttributesProtection
attribute :name, String
end
class UsersController < ApplicationController
# ...
def create
# ...
@user = User.new(user_params)
end
private
def user_params
params.require(:user).permit(:name)
end
end
Except mine isn't a user model. It's a form object that creates the other models.
See: http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
So you're saying it works fine with Virtus? If yes I should probably close this issue.
@solnic yes it works perfectly fine, params.require(:user).permit(:name)
just returns back a hash of approved values.
OK cool :)
I was wondering how to use strong_parameters with virtus gem
This is a stab for strong_parameters
Is this the right approach.