使用 Devise 嵌套资源 - Rails3
我正在尝试设置一个配置文件控制器来与设备注册成员一起使用。
我已经创建了 Profile
模型 &控制器,并通过将 belongs_to :member
添加到我的 profile.rb 模型和 has_one :profile< 来添加
一对一关系
/code> 在我的 member.rb 模型中。
要创建我使用的嵌套资源:
devise_for :members, :path => "accounts",:path_names => { :sign_in => "login", :sign_out => "logout", :sign_up => "register" }
resources :members do
resources :profiles
end
调用 rake paths
输出
member_profiles GET /members/:member_id/profiles(.:format) {:action=>"index", :controller=>"profiles"}
POST /members/:member_id/profiles(.:format) {:action=>"create", :controller=>"profiles"}
new_member_profile GET /members/:member_id/profiles/new(.:format) {:action=>"new", :controller=>"profiles"}
edit_member_profile GET /members/:member_id/profiles/:id/edit(.:format) {:action=>"edit", :controller=>"profiles"}
member_profile GET /members/:member_id/profiles/:id(.:format) {:action=>"show", :controller=>"profiles"}
PUT /members/:member_id/profiles/:id(.:format) {:action=>"update", :controller=>"profiles"}
DELETE /members/:member_id/profiles/:id(.:format) {:action=>"destroy", :controller=>"profiles"}
在浏览器中转到 localhost:3000/members/1/profiles
正确地将我路由到 profiles# index
页面,但是当我尝试调用 member_profiles_path
时,它失败并出现以下错误:
No route matches {:controller=>"profiles"}
任何人都可以看到我在这里出错的地方吗?我正在使用 Rails 3.0.3。
I'm trying to setup a profiles controller to work with devise registered members.
I've created the Profile
model & controller and added a one-to-one relationship
by adding belongs_to :member
to my profile.rb model and has_one :profile
in my member.rb model.
To create the nested resource I used:
devise_for :members, :path => "accounts",:path_names => { :sign_in => "login", :sign_out => "logout", :sign_up => "register" }
resources :members do
resources :profiles
end
Calling rake routes
outputs
member_profiles GET /members/:member_id/profiles(.:format) {:action=>"index", :controller=>"profiles"}
POST /members/:member_id/profiles(.:format) {:action=>"create", :controller=>"profiles"}
new_member_profile GET /members/:member_id/profiles/new(.:format) {:action=>"new", :controller=>"profiles"}
edit_member_profile GET /members/:member_id/profiles/:id/edit(.:format) {:action=>"edit", :controller=>"profiles"}
member_profile GET /members/:member_id/profiles/:id(.:format) {:action=>"show", :controller=>"profiles"}
PUT /members/:member_id/profiles/:id(.:format) {:action=>"update", :controller=>"profiles"}
DELETE /members/:member_id/profiles/:id(.:format) {:action=>"destroy", :controller=>"profiles"}
Going to localhost:3000/members/1/profiles
in the browser correctly routes me to the profiles#index
page, but when I try calling member_profiles_path
it fails with the following error:
No route matches {:controller=>"profiles"}
Can anyone see where I'm going wrong here? I'm using rails 3.0.3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于这是一个 has_one 关联,您是否尝试过使用资源而不是资源?
然后你应该能够做这样的事情:
Since this is a has_one association, have you tried using resource rather than resources?
You should then be able to do something like this: