Rails 3 - Devise Gem - 如何通过CRUD接口管理用户
Devise gem 用于身份验证。我需要有一个用户索引和显示视图。在 devise wiki 上找到了这个如何做,但无论如何尝试,都无法使其工作。
方法 1:记住从 Devise 模型中删除 :registerable 模块(在我的例子中是 User 模型)确保将你的 map.resources :users 放在 map.devise_for :users 路由下面(devise_for:Rails 3 的用户和资源:用户)。
方法二:devise_for :users, :path_prefix => 'd' resources :users 将设计逻辑与您的 CRUD 用户控件隔离
我的问题: 1.如果在模型中删除可注册的内容,那么设计如何为用户工作? 2.如果你这样做了,你能提供样品吗?
提前致谢
Devise gem is used for authentication. I need to have a user index and show view. Found this how to at the devise wiki, however played around, can not make it work.
Devise - How To: Manage users through a CRUD interface
Method 1: Remember to remove the :registerable module from the Devise model (in my case it was the User model) Make sure to put your map.resources :users below the map.devise_for :users route (devise_for :users and resources :users for Rails 3).
Method 2: devise_for :users, :path_prefix => ‘d’ resources :users to isolate the devise logic from your crud user controlle
My question:
1. if you remove registerable in the model, then how does devise work for user?
2. If you done this, can you provide a sample?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下内容对我有用。
users_controller.rb
routes.rb
我希望这可以帮助你。
问候,
贾科莫
The following worked for me.
users_controller.rb
routes.rb
I hope this can help you.
Regards,
Giacomo
通过将适当的 new.html.erb、edit.html.erb、_form.html.erb 等文件放入 User Views 文件夹中,添加/编辑/删除用户的工作方式应该与任何其他 CRUD 没有什么不同,因为 Devise 的 User 是另一个模型像任何一样。我不会发布新的或编辑的 erbs (足够简单,脚手架可以向您展示其余部分),但我的 User _form.html.erb 的一个示例...
在我的中,我想我留下了 :registerable ,并且我我仍然能够通过 CRUD 管理和更新用户。如果您将其省略,则用户无法自行注册,但您仍然可以自己添加和编辑用户(当然,将使用 load_and_authorize_resource 保护用户控制器以将常规用户排除在外)。
By placing the appropriate new.html.erb, edit.html.erb, _form.html.erb etc files in the User Views folder, adding/editing/deleting Users should work no differently as any other CRUD, as Devise's User is another model like any. I won't post the new or edit erbs (simple enough, and a scaffold can show you the rest), but an example of my User _form.html.erb...
In mine, I think I left :registerable in and I'm still able to administer and update users via the CRUD. If you leave it out, then users can't register themselves, but you can still add and edit users yourself (would protect the Users controller with load_and_authorize_resource to keep regular users out, of course).