2015-02-06 27 views
0

我已經創建了一個自定義註冊控制器,以在註冊時添加用戶名和姓。現在我似乎無法讓控制器允許用戶更新相同的信息。不能重寫設計註冊控制器

這是我的自定義登記控制器的末尾:

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 

更新我的日誌後顯示30​​2錯誤,我重定向去根URL不是edit_user_registration_path和記錄不會被更新。我基本上是以下這一點:

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

這裏是我的設計路線:

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 

和我的日誌:

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

我回頭一看,我的註冊現在系統也壞了。不知道我做了什麼。我的devise_for控制器語句似乎被忽略。我的註冊系統具有嵌套屬性和額外的用戶字段,這也失敗了。即使字段有效,表單也會返回驗證錯誤。

更多的代碼上要點是:https://gist.github.com/jasper502/065a63fde266fac1fbf5

回答

相關問題