我想做一個管理員帳戶來驗證用戶的註冊,因爲我有2個設計模型:管理員和用戶。Rails的3.0設計帳戶驗證從管理員到用戶 - 未定義的方法`edit_user_path'
我已經按照下列步驟操作:
https://github.com/plataformatec/devise/wiki/How-To%3a-Require-admin-to-activate-account-before-sign_in
但是從視圖中我得到這個錯誤:
未定義的方法`edit_user_path」
這是我的應用程序/模型/用戶。 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
應用/視圖/ 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 「編輯」,編輯用戶路徑(用戶)
http://thekindofme.wordpress.com/2010/01/31/notes-on-setting-up-devise-authentication-solution-for-rails/ – prusswan