gpt4 book ai didi

ruby-on-rails - 为什么在使用 CanCan 时出现名称错误

转载 作者:行者123 更新时间:2023-12-04 06:09:17 26 4
gpt4 key购买 nike

首先,我登录 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`初始化'
    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

应用程序/ Controller /application_controller.rb:21:in new'
app/controllers/application_controller.rb:21:in
current_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

订单 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

更新:

模型/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

最佳答案

# is there a models/order.rb?
class Order
end

关于ruby-on-rails - 为什么在使用 CanCan 时出现名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14128054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com