English 中文(简体)
海关登记主计长
原标题:Custom Registrations Controller for Devise not Overriding Create Action

I have been fighting with this for days now. I have created my own Registrations Controller to allow for an amdin to create and delete users. I have left the :registerable module in my devise configuration, as I also want to users to be able to edit their profiles. I have tried taking that module out just to see if it would solve my issue. The problem that I have, is that when I create a new user as an admin, it still signs that user in, despite having my own create action. I have tried everything that I can think of to get beyond this and I am stuck.

我的登记 主计长:

  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

申请管理员:=>注: subsequently_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 File:

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

Rake Lines Output:

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个用户,则每一次都要签署、签署和签署一份巨大的文件。

在这方面的任何帮助都受到高度赞赏。

最佳回答

关于您路线的第三行,我想到的是: Controllers => ......,而不是: Controller => ......。 页: 1

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签