how to add name field to devise controller

39 views
Skip to first unread message

mack gille

unread,
Jul 8, 2013, 5:52:02 AM7/8/13
to rubyonra...@googlegroups.com
hi all,
how to add name field to devise controller.

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Jul 8, 2013, 6:18:35 AM7/8/13
to rubyonra...@googlegroups.com
On 8 July 2013 10:52, mack gille <li...@ruby-forum.com> wrote:
> hi all,
> how to add name field to devise controller.

Have a look at [1], it may be helpful.

[1] https://www.google.co.uk/search?q=how+to+add+name+field+to+devise+controller&ie=UTF-8

Colin

mack gille

unread,
Jul 8, 2013, 8:27:26 AM7/8/13
to rubyonra...@googlegroups.com
Colin Law wrote in post #1114719:
i din't get any sources colin

Colin Law

unread,
Jul 8, 2013, 8:31:01 AM7/8/13
to rubyonra...@googlegroups.com
On 8 July 2013 13:27, mack gille <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1114719:
>> On 8 July 2013 10:52, mack gille <li...@ruby-forum.com> wrote:
>>> hi all,
>>> how to add name field to devise controller.
>>
>> Have a look at [1], it may be helpful.
>>
>> [1]
>>
> https://www.google.co.uk/search?q=how+to+add+name+field+to+devise+controller&ie=UTF-8
>>
>> Colin
>
> i din't get any sources colin

Did not [2] help? For me it was linked to by the second result in
google (the first was your question itself).

Colin

[2] http://eureka.ykyuen.info/2011/03/03/rails-%E2%80%93-add-custom-fields-to-devise-user-model/

mike

unread,
Jul 8, 2013, 9:58:02 AM7/8/13
to rubyonra...@googlegroups.com, cla...@googlemail.com
There's one update to these links.  These links tell you to add your attribute (in your case, :username) to attr_accessible in the model user.rb.  Devise has be re-written since these links were written to use strong parameters.  Instead of adding the attr_accessible line to your model, you need to create a custom controller which is a bit of work.  Following the example of these links, to add the attribute :username to the model users, you would add the following users_controller.rb:

class UsersController < Devise::RegistrationsController

   private
   
      def sign_up_params
         params.require(:user).permit(:username, :email, :password, :password_confirmation)
      end

      def account_update_params
         params.require(:user).permit(:username, :email, :password, :password_confirmation, :current_password)
      end

end

Note that the controller inherits from Devise::RegistrationsController, not ApplicationController.

You will then need to change your routes in config/routes.rb by adding the following lines:

   devise_for :users, :controllers => { :registrations => "users" }

   devise_scope :user do
      resources :users
   end

This is, obviously, considerable more work but will be necessary going forward with strong parameters.

The other steps in the links provided still apply.


Colin Law

unread,
Jul 8, 2013, 10:19:29 AM7/8/13
to rubyonra...@googlegroups.com
That is good to know, thanks Mike.

Colin
Reply all
Reply to author
Forward
0 new messages