1

嗨,任何机构都可以解决这个错误,因为我正在 NoMethodError为我的 prop_manager_controller.rb

PropManagerController 中的 NoMethodError#new

undefined method `prop_manager?' for #<User:0x471f690>    

控制器

class PropManagerController < ApplicationController

  before_filter :login_required, :except => [:new, :create]
  load_and_authorize_resource

  # GET /prop_manager
  # GET /prop_manager.json

  def index
    @prop_managers= PropManager.order('id:desc').page(params[:page])
    respond_to do |format|
      format.html #index.html.erb
      format.json {render json: @prop_managers}      
    end
  end

  # GET /prop_manager
  # GET /prop_manager.json

  def show
    @prop_managers= PropManager.order('id:desc').page(params[:page])
    respond_to do |format|
      format.html #show.html.erb
      format.json {render json:@prop_managers}
    end
  end

  # GET /prop_manager
  #GET /prop_manager.json

  def new
    @prop_managers= PropManager.new
      respond_to do |format|
        format.html #new.html.erb
        format.json {render json:@prop_managers}
      end
  end

  # GET /prop_manager/1/edit
  def edit
    @prop_manager = PropManager.find(params[:id])
  end

  # POST /prop_managers
  # POST /prop_managers.json
  def create
    @prop_manager = PropManager.new(params[:prop_manager])
    respond_to do |format|
      if @prop_manager.save
        #UserMailer.delay.homeowner_welcome_email(@home_owner, params[:home_owner][:password])
        UserMailer.propmanager_welcome_email(@prop_manager, params[:prop_manager][:password]).deliver
        format.html { redirect_to prop_manager_path(@prop_manager), notice: 'PropManager was successfully created.' }
        format.json { render json: @prop_manager, status: :created, location: @prop_manager }
      else
        @prop_manager.errors[:base] << @exception_message
        format.html { render "new" }
        format.json { render json: @prop_manager.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /prop_manager/1
  # PUT /prop_manager/1.json

  def update
    @prop_manager = PropManager.find(params[:id])
    @prop_manager.card_validity = nil
    begin
      customer = Stripe::Customer.retrieve(@prop_manager.stripe_customer_id)
      customer.email = params[:prop_manager][:email]
      customer.card = { :number => params[:prop_manager][:credit_card_number],
                    :exp_month => params[:prop_manager][:credit_card_expiry_month],
                    :exp_year => params[:prop_manager][:credit_card_expiry_year],
                    :cvc => params[:prop_manager][:credit_card_cvc_code],
                    :name => params[:prop_manager][:credit_card_holder_name] }

      customer.save
      @prop_manager.card_validity = true
    rescue => exception
      @exception_message = exception.message
    end
    respond_to do |format|
      if @prop_manager.update_attributes(params[:prop_manager])
        format.html { redirect_to home_owner_path(@prop_manager), notice: 'PropManager account details updated successfully.' }
        format.json { head :ok }
      else
        @prop_manager.errors[:base] << @exception_message
        format.html { render action: "edit" }
        format.json { render json: @prop_manager.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /home_owners/1
  # DELETE /home_owners/1.json

  def destroy
    @prop_manager = PropManager.find(params[:id])

    begin
      customer = Stripe::Customer.retrieve(@prop_manager.stripe_customer_id)
      customer.delete
    rescue => exception
      # Do nothing - there is no customer record in the stripe account
    end
    @prop_manager.destroy

    respond_to do |format|
      format.html { redirect_to prop_managers_url }
      format.json { head :ok }
    end
  end
end

路线

GEMS::Application.routes.draw do
  resources :customer_feedbacks

  resources :general_repairs_prices
  resources :steam_cleaning_prices
  resources :window_cleaning_prices
  resources :roof_cleaning_prices
  resources :gutter_cleaning_prices

  resources :residential_jobs do
    member do
      get 'accept'
      get 'decline'
      get 'print_friendly'
    end
    collection do
      post 'create_job_with_estimate'
      put 'update_multiple'
    end
    resources :residential_job_changes do
      member do
        get 'approve'
      end
    end
  end

  resources :home_owners 
  resources :prop_managers 

  resources :contractors do
    member do
      get 'approve'
      get 'disapprove'
    end
  end

  resources :users
  resources :email_templates
  resources :feedback_survey_questions
  resources :decline_reasons
  resources :services
  resources :branches
  resources :sessions
  resources :password_resets

  get "sites/index"
  get "sites/about_us"
  get "sites/home_owner"
  get "sites/home_owner_front"
  get "sites/prop_manager"
  get "sites/owner_register"

  get "login" => "sessions#new", :as => "login"
  get "logout" => "sessions#destroy", :as => "logout"

end  

我想我已经正确定义了路线,所以请让我知道需要任何更改。

4

1 回答 1

0

它看起来像:

您的 User 模型上没有该方法prop_manager?。这是您必须自己添加的方法——活动记录本身不会使方法可用,?并且可用。

从跟踪的外观来看,这可能发生在用户模型的回调中。您的用户模型中有类似的东西吗?

  • 或者 -

你正在使用我注意到的cancan。登录用户的权限可能不包括访问该方法——尽管我认为 cancan 会提供比简单地说该方法不可用更好的错误。

于 2012-05-24T10:30:09.213 回答