开发者

Problem modifying order model: uninitialized constant Order (NameError) - Spree 0.60.1

This is my first post on the list but before I ask for help I would to thank you all for the wonderful platform that you have created.

On a project I'm working on there is a need for a donation/donate functionality. I've followed the customization guide (http://spreecommerce.com/documentation/customization.html) to add new logic to the Order model.

I've added a new file called 'order_decorator.rb' inside 'app/models' and added:

Order.class_eval do
  def my_method
    # custom code
  end
end

and I'm getting the following error:

order_decorator.rb:1:in `<top (required)>': uninitialized constant Ord开发者_高级运维er (NameError)

Anyone can add some light to my problem?

This was cross posted the Spree mailing list https://groups.google.com/d/topic/spree-user/mGcj4EpGuYo/discussion


Thanks Brian (https://groups.google.com/forum/#!topic/spree-user/mGcj4EpGuYo/discussion) for the fix. In spree the require statement needed to add all the files that end with '_decorator' need to go inside the 'self.activate' block:

module SpreeSite
  class Engine < Rails::Engine
    def self.activate
      # Add your custom site logic here
      Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
        Rails.configuration.cache_classes ? require(c) : load(c)
      end
      AppConfiguration.class_eval do
       #
      end
    end

    def load_tasks
    end

    config.to_prepare &method(:activate).to_proc
  end
end


That is breaking the Rails naming scheme. Either change the file name to order.rb or the code to OrderDecorator.class_eval do ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜