Ruby on rails “轨道不接触”;关注点;?
在我的推车控制器中,我有:Ruby on rails “轨道不接触”;关注点;?,ruby-on-rails,ruby,Ruby On Rails,Ruby,在我的推车控制器中,我有: class CartsController < ApplicationController before_action :set_cart, only: [:show, :edit, :update, :destroy] rescue_from ActiveRecord::RecordNotFound, with: :invalid_cart 但是当我点击“添加到购物车”时,我得到了错误消息 "undefined method `set_cart' f
class CartsController < ApplicationController
before_action :set_cart, only: [:show, :edit, :update, :destroy]
rescue_from ActiveRecord::RecordNotFound, with: :invalid_cart
但是当我点击“添加到购物车”时,我得到了错误消息
"undefined method `set_cart' for #<CartsController"
“未定义的方法`set#u cart'”您需要包括您的模块:
class CartsController < ApplicationController
include CurrentCart
before_action :set_cart, only: [:show, :edit, :update, :destroy]
rescue_from ActiveRecord::RecordNotFound, with: :invalid_cart
class CartsController
可能是一个愚蠢的问题,但你是否在控制器中包含了你的模块?当我参与进来时,这不是一个愚蠢的问题。carts controller中添加的模块是什么样子的?@BroiSatse你应该有一行包含CurrentCart
@BroiSatse明白了。你是一个乐于助人的人。我不知道如何给你“分数”或者通过评论给你加冕。
class CartsController < ApplicationController
include CurrentCart
before_action :set_cart, only: [:show, :edit, :update, :destroy]
rescue_from ActiveRecord::RecordNotFound, with: :invalid_cart