0

I am a beginner to RoR and could use some guidance. I have been trolling this stackoverflow answer religiously these past few days.

Rails engines extending functionality

But the error that keeps being thrown is: 'undefined method join'

I have an abstract model called OrderError. OrderErrorDetails is my other model , which is used to actually store data within the database. The OrderError abstract model is here solely to provide functionality, not to store anything. :

module MyEngine
  class OrderError
    self.abstract_class = true
    has_one :order_error_detail

    def self.new
      #my_code
    end

  end
end

So what I tried instead of requiring (stack overflow link above) was placing the following code to my app's Order Model:

order_error MyEngine::OrderError.new

When I did this, I was able to successfully access my engines OrderError model. However, the error I now get is: The method .order() must contain arguments.

My hope is that once the engine is mounted into an app, I can call my engines various methods. This will provide the user of the engine some default functionality.

Should I be using abstract classes to begin with? In my mind the answer is yes, because my abstract model's only purpose is to provide methods that can be used. If so, how does one efficiently provide access to those methods?

Community
  • 1
  • 1
James
  • 621
  • 4
  • 13
  • Have you thought about using model concerns for this instead? – Kaspar Jan 27 '15 at 19:41
  • So, in my test/dummy folder inside my Engine, I have my dummy app scaffolded with concerns. But the actual mountable engine doesn't have that same scaffolding set up. I tried replicating and repurposing some code found here: [link](http://stackoverflow.com/questions/14541823/how-to-use-concerns-in-rails-4) . But the same problem with actually being able to globally call those methods in the app that my engine is mounted on still doesn't work. Concerns seems to make things modular, but doesn't help me extend functionality. – James Jan 27 '15 at 19:58

1 Answers1

0

using:

MyEngine::OrderError.new 

is the correct way to extend engine model functionality. In the above example, the method "new" had some problems with the way it was structured. This comes down to engine namespacing. Every class is encapsulated in the module of MyEngine (The engine name). This is so that your engine code is modular and seperate from its parent app code. The best explanation for namespacing was found on the getting started with engines guide here: http://guides.rubyonrails.org/v3.2.13/engines.html#what-are-engines

James
  • 621
  • 4
  • 13