Ruby on rails 用用户模型和STI设计,注册时控制器错误
我曾经有一段时间使用Deviate的用户模型,现在我必须在应用程序中添加一个新模型,名为Profile,由于它与用户的属性几乎相同,我决定从用户那里继承Profile user.rbRuby on rails 用用户模型和STI设计,注册时控制器错误,ruby-on-rails,ruby-on-rails-4,devise,Ruby On Rails,Ruby On Rails 4,Devise,我曾经有一段时间使用Deviate的用户模型,现在我必须在应用程序中添加一个新模型,名为Profile,由于它与用户的属性几乎相同,我决定从用户那里继承Profile user.rb class User < ActiveRecord::Base ... end 耙路径 user_registration POST / users/registrations#create new_user_registration GE
class User < ActiveRecord::Base
...
end
耙路径
user_registration POST / users/registrations#create
new_user_registration GET /becometutor(.:format) users/registrations#new
profile_registration POST / profiles/registrations#create
new_profile_registration GET /brand_profile(.:format) profiles/registrations#new
问题
当我打开new\u profile\u注册时
日志显示:
Processing by Profiles::RegistrationsController#new as HTML
Processing by Users::RegistrationsController#create as JS
Parameters: {"utf8"=>"✓", "profile"=>{"name"=>"", "phone"=>"", "owner_name"=>"", "owner_phone_number"=>""
当我在应该创建配置文件的表单上单击“提交”时,日志显示:
Processing by Profiles::RegistrationsController#new as HTML
Processing by Users::RegistrationsController#create as JS
Parameters: {"utf8"=>"✓", "profile"=>{"name"=>"", "phone"=>"", "owner_name"=>"", "owner_phone_number"=>""
问题
为什么要创建指向Users::RegistrationController
,而不是Profiles::RegistrationController
多谢各位
修复-为每个资源设置不同的路径
devise_for :users, :path => 'tutors', :path_names => {:sign_up => "becometutor"},
:controllers => { :registrations => "users/registrations" }
devise_for :profiles, :path => 'profiles', :path_names => { :sign_up => "brand_profile"},
:controllers => { :registrations => "profiles/registrations" }
我不确定,但我想这是由于
routes
。如果您将profile
route置于user
route之上,它可能会工作。您可能只需将
@user
传递到表单
,它会选择用户
创建路径作为第一个路径。您有两条路径具有相同的url,用户注册帖子/
和配置文件
,因此Rails会寻找第一条路径,指向用户/注册#创建
表单是Desive中使用资源
作为对象的默认表单:表单(资源,:as=>资源名称,:url=>注册路径(资源名称)
。Artem回答解决了我的问题,谢谢。