我正在做一些测试,我建议你使用回调,但你也可以覆盖 Devise 的 RegistrationsController 的操作。我关注了这个线程:覆盖设计注册控制器和控制器的代码https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb(请参阅我使用sign_in而不是sign_up -我正在使用 Rails 3.2.8)
这是对该案例进行编辑的代码:
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
build_resource
resource.build_user_profile
resource.user_profile.language_id = 45
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
def update
super
end
end
正如帖子的答案所说,我留下的路线如下:
devise_for :users, :controllers => {:registrations => "registrations"}
我使用了has_one关系。