2012-09-14 2 views
0

레일 3.0
에서 업데이트 칼럼 : 나는 마이그레이션 발생했습니다 https://github.com/plataformatec/devise/wiki/How-To%3a-Require-admin-to-activate-account-before-sign_in : 승인 (부울) 내 유증의 user.rb.에 대한 이제 다른 컨트롤러 인 unapproved_users_controller.rb의 확인란을 사용하여 편집하고 싶습니다.
편집 할 때 양식을로드 할 때이 오류가 발생합니다 : 정의되지 않은 메서드`user_path '.레일 고안 -이 지침에 따라 다른 컨트롤러

routes.rb, 나의 새로운 컨트롤러

resources :unapproved_users 

응용 프로그램에 대한 자원/모델/user.rb는, 그 통지 : 승인이 attr_accessible입니다. unapproved_controllers.rb

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

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

    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 

응용 프로그램/컨트롤러/

class UnapprovedUsersController < ApplicationController 

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

    def edit 
    @user = User.find(params[:id]) 
    end 

    def update 
    @user = User.find(params[:id]) 
    @user.update_attributes(params[:user]) 
    end 

end 

응용 프로그램/뷰/unapproved_users/index.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_unapproved_user_path(user) 

응용 프로그램/뷰/unapproved_users/edit.html.haml

= render 'form' 

응용 프로그램/뷰/unapproved_users/_form.html.haml

= form_for (@user) do |f| 

    -if @user.errors.any? 
    #error_explanation 
     %h2= "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:" 
     %ul 
     - @user.errors.full_messages.each do |msg| 
      %li= msg 

    .field 
    = f.label :approved, 'Approved?' 
    = f.check_box :approved 
    .actions 
    = f.submit 'Save' 

답변

1

당신은 form_for을 변경해야합니다.

이 있어야한다

= form_for(@user, :url => unapproved_user_path(@user)) do |f|