管理者がユーザー登録する

ちょっと無理矢理だけど・・・できた。

正直、確実に修正対象です。。。

コントローラーを生成

rails g controller user/registration

Devise::RegistrationsControllerをオーバーライド

  • app/controllers/user/registrations_controller.rb
class User::RegistrationsController < Devise::RegistrationsController
  skip_before_filter :require_no_authentication
  before_filter :authenticate_user!

  def new
    if can? :create, User
      super
    else
      redirect_to root_path unless can? :create, User
    end
  end

  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up
        redirect_to root_path
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end
end

ページをコピー

cp app/views/devise/registrations/new.html.slim app/views/user/registrations/

コピーしたページ内の情報を送信する先のパスを変更しておくこと

  • config/routes.rb
devise_for :users, :controllers => { :registrations => "user/registrations" }, :as => ""

:as => "" はパス名が被ってしまうのでわざわざ付けました。。。正直これも気に入らないから修正対象