Rails 3 – 设计Gem – 如何通过CRUD界面管理用户

Devise gem用于身份validation。 我需要有一个用户索引和显示视图。 发现这个如何在设计维基,但无论如何玩,无法使其工作。

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

方法1:记得从Devise模型中移除:registerable模块(在我的例子中是用户模型)确保将map.resources:users放在map.devise_for:users route(devise_for:users and resources:users)下面for Rails 3)。

方法2:devise_for:users,:path_prefix =>’d’资源:用户将设计逻辑与您的crud用户控件隔离开来

我的问题:1。如果您删除模型中的可注册项,那么如何为用户设计工作? 如果你这样做了,你能提供样品吗?

提前致谢

通过在用户视图文件夹中放置相应的new.html.erb,edit.html.erb,_form.html.erb等文件,添加/编辑/删除用户应该与其他任何CRUD没有区别,因为Devise的用户是另一个模型像任何一样。 我不会发布新的或编辑erbs(简单,脚手架可以显示其余的),但我的用户_form.html.erb的一个例子…

<%= form_for(@user) do |f| %> <%= render :partial => 'shared/errors', :locals => { :content => @user } %> 
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %> (leave blank if you don't want to change it)
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<%= f.label :current_password %> (we need your current password to confirm your changes)
<%= f.password_field :current_password %>
<%= f.submit %>
<% end %>

在我的,我想我离开了:可注册,我仍然可以通过CRUD管理和更新用户。 如果你把它留下来,那么用户就无法自己注册,但你仍然可以自己添加和编辑用户(当然,用load_and_authorize_resource保护用户控制器以保持常规用户)。

以下对我有用。

users_controller.rb

 class UsersController < ApplicationController ... def create @user = User.new(params[:user]) if params[:user][:password].blank? params[:user].delete(:password) params[:user].delete(:password_confirmation) end respond_to do |format| if @user.save format.html { redirect_to users_path, notice: 'User was successfully created.' } else format.html { render action: "new" } end end end ... end 

的routes.rb

 ... devise_for :users, :path_prefix => 'd' resources :users ... 

我希望这可以帮到你。

此致,贾科莫