4

まず、 http://example--site.com/shop/walmart/order/1
にログインし ます。このようなコードで作成された [編集] ボタンを押します。

  <%= link_to t('.edit', :default => t("helpers.links.edit")),
              edit_community_order_path(@community, @order), :class => 'btn' %>

このエラーを返します。なぜ?

ログエラー (名前エラー!)

Started GET "/shop/walmart/order/1/edit"Processing by OrdersController#edit as HTML
  Parameters: {"community_id"=>"walmart", "id"=>"1"}
  [1m[36mCommunity Load (0.5ms)[0m  [1mSELECT `communities`.* FROM `communities` WHERE `communities`.`community_name` = 'walmart' AND (`communities`.`deleted_at` IS NULL) LIMIT 1[0m
  [1m[35mUser Load (0.4ms)[0m  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 AND (`users`.`deleted_at` IS NULL) LIMIT 1
Completed 500 Internal Server Error in 74ms

NameError (uninitialized constant Ability::Order):
  app/models/ability.rb:26:in `initialize'
  app/controllers/application_controller.rb:21:in `new'
  app/controllers/application_controller.rb:21:in `current_ability'

これが私のコードです。

app/models/ability.rb:26:in `initialize'

    if user
        can :read, :all 
        can [:create, :destroy], Comment, {:user_id => user.id}
        can [:create, :update], Community, {:user_id => user.id}
26>     can [:create, :update], Order, {:user_id => user.id}
        can [:create, :update], CommunityTopic, {:user_id => user.id}
    else
        can :read, :all

    end

app/controllers/application_controller.rb:21:in new' app/controllers/application_controller.rb:21:incurrent_ability'

    #CanCan
    private 
    def current_ability 
21>     @current_ability ||= Ability.new(current_user) 
    end

ルート.rb

resources :communities, :path => "shop", do
    resources :orders, :path => "order"
end 

orders_controller.rb

load_and_authorize_resource :community, :find_by => :community_name
load_and_authorize_resource :through => :community, :shallow => true
…..
  # GET /orders/1/edit
  def edit
  end

アップデート:

models/order.rb

class Order < ActiveRecord::Base

  attr_accessible :deleted_at, :code, :community_id, :greeting, :user_id, :visible
  belongs_to :user
  belongs_to :community

  acts_as_paranoid

end
4

1 に答える 1

2
# is there a models/order.rb?
class Order
end
于 2013-01-02T20:28:44.477 に答える