Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will need to put your module_eval code into a <code>config.to_prepare do</code> block. The easiest place to do this is in <code>config/application.rb</code> or to create an engine. The code is identical except it executes every time you run the site not just the first time (which especially applies to development mode) and code which only executes before the initialisation process (aka requiring files) into a <code>config.before_initialize do</code> block.</p> <p>The reason that <code>config.to_prepare</code> is important is because in development mode, the code is reloaded on every request but initializers generally aren't. This means that <code>Page</code>, which you are running a module_eval on, will only have the module_eval run once but will reload itself every request. <code>config.to_prepare</code> is a Rails hook that runs every single time providing great convenience for situations like this.</p> <h3>config/application.rb approach</h3> <pre><code>class Application &lt; Rails::Application # ... other stuff ... config.before_initialize do require 'page_extensions' end config.to_prepare do Page.send :include, Pants::Extensions::Page end end </code></pre> <h3>Engine approach</h3> <p>If you don't want to modify <code>config/application.rb</code> then you can, in Refinery CMS, create <code>vendor/engines/add_page_extensions/lib/add_page_extensions.rb</code> which would look like this:</p> <pre><code>require 'refinery' module Refinery module AddPageExtensions class Engine &lt; Rails::Engine config.before_initialize do require 'page_extensions' end config.to_prepare do Page.send :include, Pants::Extensions::Page end end end end </code></pre> <p>If you use the engines approach you will also need to create <code>vendor/engines/add_page_extensions/add_page_extensions.gemspec</code> which should contain a simple gemspec:</p> <pre><code>Gem::Specification.new do |s| s.name = 'add_page_extensions' s.require_paths = %w(lib) s.version = 1.0 s.files = Dir["lib/**/*"] end </code></pre> <p>And then in your <code>Gemfile</code> add this line:</p> <pre><code>gem 'add_page_extensions', :path =&gt; 'vendor/engines' </code></pre> <p>If you go the engine approach, you will probably want to put all of your logic inside the engine's <code>lib</code> directory including the <code>Pants::Extensions::Page</code> code.</p> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload