Reputation: 3383
Greeting,
I've been working on getting my devise sign up form customized for my application, and it's been a bit of a pain trying to sort out how Devise is handling things. My form is customized, but my the attributes in my new fields are not being saved to the database. I looked at something like this solution:http://blog.12spokes.com/web-design-development/adding-custom-fields-to-your-devise-user-model-in-rails-4/ (yeah it's for rails 4) but.... it doesn't feel like the cleanest way to do this. I'd like to know if there is a more efficient way of doing this now. Would you recommend moving additional user information that is unrelated to Devise authentication into a new table? If so, can I put fields for some nested elements in the Devise sign-up form without having to go through all of business in the solution above. Thanks in advance!
Upvotes: 0
Views: 111
Reputation: 2393
What about trying to use the devise_parameter_sanitizer
:
application_controller.rb
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
private
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:additional_field1, :additional_field2, :email, :password, :password_confirmation) }
end
end
and then on your User
model, you could simply add validation :
user.rb
class User < ActiveRecord::Base
validates :additional_field1, presence: true
validates :additional_field2, uniqueness: true
end
Upvotes: 1