Reputation: 899
Hi i am currently working on my Ruby on Rails project and i wanted to customize the devise gem but my problem is that i cant seem to find some tutorials on how to customize devise more specifically customizing the login, parameters.
I already customized the login and the view of the device , but my problem is it doesn't seem to create the username , firstname , lastnamge , age , etc.
and it only gets the email and password etc. the basic stuff
i know the documentation is great and all specially because it is complete but my problem is that i find it a bit hard to follow specially when i cant see the video or how can i customize what i can put inside in the devise if anybody can help me with this , or any information on some tutorials with actually doing what i specified above that would be great and will really be appreciated , and please i am a bit new on RoR so i find it a bit difficult in just reading the text so i need some vdeo and thanks!
simplybel@simplybel:~/projects/gamification$ rails c
Loading development environment (Rails 4.1.6)
2.1.2 :001 > User.all
User Load (0.8ms) SELECT "users".* FROM "users"
=> #<ActiveRecord::Relation [#<User id: 7, first_name: nil, last_name: nil, profile_name: nil, email: "[email protected]", encrypted_password: "$2a$10$xg.HMU2JljnVLls3IX7Go.IfJVLGYSSRePjtDaYS4nE...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2014-12-01 23:50:17", last_sign_in_at: "2014-12-01 23:50:17", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2014-12-01 23:50:17", updated_at: "2014-12-01 23:50:17">]>
2.1.2 :002 >
this is the what the rails console returned after taking your advice, here is the code that you can clone
https://github.com/sanchez900/gamification.git
that is the code before I did the changes like the
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :username
end
end
i also did this
rails generate devise:views
also did the controllers rails generate devise:controllers users
did the routes devise_for :users, controllers: { sessions: "users/sessions" }
some other info might help also the project clone / link is before i did the modifications
Upvotes: 0
Views: 114
Reputation: 692
If you had setup your view correctly to submit all the addition parameters, then you need to do as instructed in the docs https://github.com/plataformatec/devise#strong-parameters.
You need to update your permitted parameters on your sign up form to accept the new parameters you need. To do this, you can set a before filter to configure the permitted params for your devise controllers. Try something like this in your application controller.
before_action :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :profile_name) }
end
Upvotes: 1