Rails 3 - Devise Gem - 如何通过 CRUD 界面管理用户 [英] Rails 3 - Devise Gem - How to Manage Users through CRUD interface

查看:14
本文介绍了Rails 3 - Devise Gem - 如何通过 CRUD 界面管理用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设计 gem 用于身份验证.我需要一个用户索引并显示视图.在设计维基上找到了这个方法,但是怎么玩,都不能让它工作.

设计 - 如何: 通过 CRUD 界面管理用户

方法 1:记得从 Devise 模型中删除 :registerable 模块(在我的例子中它是 User 模型)确保将您的 map.resources :users 放在 map.devise_for :users 路由下面(devise_for :users 和资源:Rails 3 的用户).

方法 2:devise_for :users, :path_prefix => ‘d’ resources :users 将设计逻辑与 crud 用户控制隔离

我的问题:1.如果在模型中去掉registerable,那么devise对用户是如何工作的?2.如果你这样做了,你能提供一个样本吗?

提前致谢

解决方案

通过在 User Views 文件夹中放置适当的 new.html.erb、edit.html.erb、_form.html.erb 等文件,添加/编辑/删除用户应该与任何其他 CRUD 没有什么不同,因为 Devise 的用户是另一个模型.我不会发布新的或编辑的 erb(足够简单,脚手架可以向你展示其余的),而是我的用户 _form.html.erb 的一个例子......

<%= form_for(@user) do |f|%><%=渲染:部分=>'共享/错误', :locals =>{:内容=>@用户}%><div class="field"><%= f.label :email %><br/><%= f.text_field :email %>

<div class="field"><%= f.label :password %><i>(如果您不想更改,请留空)</i><br/><%= f.password_field :password %>

<div class="field"><%= f.label :password_confirmation %><br/><%= f.password_field :password_confirmation %>

<div class="field"><%= f.label :current_password %><i>(我们需要您当前的密码来确认您的更改)</i><br/><%= f.password_field :current_password %>

<div class="actions"><%= f.submit %>

<%结束%>

在我的,我想我离开了 :registerable in 并且我仍然能够通过 CRUD 管理和更新用户.如果您将其省略,则用户将无法自行注册,但您仍然可以自行添加和编辑用户(当然,会使用 load_and_authorize_resource 保护用户控制器以防止普通用户进入).

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

解决方案

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...

<%= form_for(@user) do |f| %>
   <%= render :partial => 'shared/errors', :locals => { :content => @user } %>

   <div class="field">
      <%= f.label :email %><br />
      <%= f.text_field :email %>
   </div>   

   <div class="field">  
      <%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
      <%= f.password_field :password %>
   </div>

   <div class="field">
      <%= f.label :password_confirmation %><br />
      <%= f.password_field :password_confirmation %>
   </div>

   <div class="field">
      <%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
      <%= f.password_field :current_password %>
   </div>

   <div class="actions">
      <%= f.submit %>
   </div>

<% end %>

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).

这篇关于Rails 3 - Devise Gem - 如何通过 CRUD 界面管理用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆