我一直在爲此奮戰數日。我創建了自己的註冊控制器,以允許創建和刪除用戶。我已將:registerable
模塊留在了我的設計配置中,因爲我還希望用戶能夠編輯其配置文件。我試圖把這個模塊拿出來看看它是否能解決我的問題。我遇到的問題是,當我創建一個新用戶作爲管理員時,儘管擁有自己的創建操作,但仍然會將該用戶標記爲該用戶。我嘗試了所有我能想到的超越這一點的東西,而且我被卡住了。自定義註冊控制器設計不覆蓋創建行動
我的註冊記憶控制器:
class RegistrationsController < Devise::RegistrationsController
load_and_authorize_resource
def new
super
end
def create
resource.build
if resource.save
redirect_to users_path
else
clean_up_passwords(resource)
render_with_scope :new
end
end
end
應用控制器:=>注,after_sign_up_path_for
在這裏重寫作爲一個測試,看看是否能夠工作
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from CanCan::AccessDenied do |exception|
flash[:error] = exception.message
redirect_to projects_url
end
protected
def stored_location_for(resource)
nil
end
def after_sign_in_path_for(resource)
projects_url
end
def after_sign_up_path_for(resource)
users_path
end
end
routes文件:
DeviseTest::Application.routes.draw do
devise_for :users, :controller => { :registrations => "registrations"}
devise_scope :user do
get '/login' => 'devise/sessions#new'
get '/logout' => 'devise/sessions#destroy'
end
resources :users, :controller => "users"
resources :projects
root :to => 'home#index'
end
和我的用戶管理員視圖的控制器
條class UsersController < ApplicationController
load_and_authorize_resource
# GET /users
# GET /users.xml
def index
@users = User.excludes(:id => current_user.id)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
end
# DELETE /users/1
# DELETE /users/1.xml
def destroy
@user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.html { redirect_to(users_url) }
format.xml { head :ok }
end
end
end
耙路線輸出:如預期
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
login GET /login(.:format) {:controller=>"devise/sessions", :action=>"new"}
logout GET /logout(.:format) {:controller=>"devise/sessions", :action=>"destroy"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
projects GET /projects(.:format) {:action=>"index", :controller=>"projects"}
POST /projects(.:format) {:action=>"create", :controller=>"projects"}
new_project GET /projects/new(.:format) {:action=>"new", :controller=>"projects"}
edit_project GET /projects/:id/edit(.:format) {:action=>"edit", :controller=>"projects"}
project GET /projects/:id(.:format) {:action=>"show", :controller=>"projects"}
PUT /projects/:id(.:format) {:action=>"update", :controller=>"projects"}
DELETE /projects/:id(.:format) {:action=>"destroy", :controller=>"projects"}
root /(.:format) {:controller=>"home", :action=>"index"}
其他一切作品,我只是不能創建的用戶沒有簽署這不是一個巨大的問題創建一個用戶,但如果我需要的。要創建3個或4個,每次登錄,簽名都是一個巨大的皮塔餅。
對此非常感謝。
什麼'rake routes'輸出? – cbrauchli
添加了耙路輸出。 – janders223