0

我正在尝试创建一个管理员帐户来验证用户的注册,因为我有 2 个设计模型:管理员和用户。

我已按照以下步骤操作:
https ://github.com/plataformatec/devise/wiki/How-To%3a-Require-admin-to-activate-account-before-sign_in

但是从视图中我得到了这个错误:
未定义的方法`edit_user_path'

这是我的 app/models/user.rb

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :remember_me

  def active_for_authentication? 
    super && approved? 
  end 

  def inactive_message 
    if !approved? 
      :not_approved 
    else 
      super # Use whatever other message 
    end 
  end

  def self.send_reset_password_instructions(attributes={})
    recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
    if !recoverable.approved?
      recoverable.errors[:base] << I18n.t("devise.failure.not_approved")
    elsif recoverable.persisted?
      recoverable.send_reset_password_instructions
    end
    recoverable
  end
end

应用程序/控制器/unapproved_users_controller.rb

class UnapprovedUsersController < ApplicationController

  def index
    if params[:approved] == "false"
      @users = User.find_all_by_approved(false)
    else
      @users = User.all
    end
  end
end

应用程序/views/unapproved_users.html.haml

%h1 Users

= link_to "All Users", :action => "index"
|
= link_to "Users awaiting approval", :action => "index", :approved => "false"

%table
    - @users.each do |user|
        %tr
            %td= user.email
            %td= user.approved
            %td= link_to "Edit", edit_user_path(user)

此路径导致问题:
= link_to "Edit", edit_user_path(user)

4

1 回答 1

1

选项 #1 - 检查rake routes正确的助手

选项#2 - 您需要设置一个管理员界面来编辑用户,因为我很确定设计只为current_user想要编辑另一个用户的人提供界面。

选项 #3 - 使用类似RailsAdmin 的东西

于 2012-09-13T22:35:04.530 回答