1
votes

I have already created a custom registrations controller to add users first and last names when signing up. Now I can't seem to get the controller to allow the users to update the same info.

This is the end of my custom registrations controller:

  protected

  ### CUSTOM ###

  def sign_up_params

    #devise_parameter_sanitizer.sanitize(:sign_up)
    params.require(:user).permit(:email, :password, :password_confirmation, :name_first, :name_last, :phone, roles_attributes: [ company_attributes: [ :id, :name, :address1, :address2, :city, :province, :postal ] ] )

  end

  def account_update_params
    params.require(:user).permit(:email, :password, :password_confirmation, :current_password, :name_first, :name_last, :phone, :mobile, :title, :location, :timezone )
  end


  def after_update_path_for(resource)
    edit_user_registration_path
  end

After updating my logs show a 302 error and my redirect goes to the root URL not the edit_user_registration_path and the record is NOT updated. I am basically following this:

http://www.jacopretorius.net/2014/03/adding-custom-fields-to-your-devise-user-model-in-rails-4.html

Here are my Devise routes:

  devise_for :users, :skip => [:sessions, :registrations], :controllers => { :registrations => 'users/registrations', :sessions => 'users/sessions' }
  as :user do
    #resource :registration, only: [:new, :create, :edit, :update]
    get "/register" => "devise/registrations#new", :as => :user_registration
    get "/account/profile" => "devise/registrations#edit", :as => :edit_user_registration
    patch "/account/profile" => "devise/registrations#update"
    put "/account/profile" => "devise/registrations#update", :as => :update_user_registration
    get '/signin' => 'devise/sessions#new', :as => :new_user_session
    post '/signin' => 'devise/sessions#create', :as => :user_session
    delete '/signout' => 'devise/sessions#destroy', :as => :destroy_user_session
  end

and my logs:

Processing by Devise::RegistrationsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Q6T3nT9Z5h+n6BLP27wQ1F3UZ+Zp9t8Y/rLxIkEMYWM=", "user"=>{"email"=>"xxxxxxxx", "name_first"=>"xxx", "name_last"=>"xxxx", "phone"=>"xxxxxxx", "mobile"=>"", "title"=>"", "location"=>"", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Update"}
Redirected to http://localhost:3000/
Completed 302 Found in 83ms (ActiveRecord: 0.7ms)
Started GET "/" for 127.0.0.1 at 2015-02-06 01:25:25 -0700
Processing by IndexController#landing as HTML
  Rendered index/landing.html.erb within layouts/landing (0.0ms)
Completed 200 OK in 6ms (Views: 5.3ms | ActiveRecord: 0.3ms)

UPDATE

I looked back and my registration system is broken now too. Not sure what I did. My devise_for controller statement seems to be ignored. My registration system has nested attributes and additional user field and that is failing too. The form kicks back validation errors even when the fields are valid.

More code on Gist: https://gist.github.com/jasper502/065a63fde266fac1fbf5

1

1 Answers

0
votes

See this updated question: Devise with additional user fields, nested models / attributes and custom routes

I ended up changing my routes to "user/..." from "devise/..." and that seemed to do the trick.

Full Gist here: https://gist.github.com/065a63fde266fac1fbf5.git