Note that there are some explanatory texts on larger screens.

plurals
  1. PORails3 Engine -- Controller scoped inside engine module returning load error by client app
    text
    copied!<p>I just created my first engine. It adds a couple of new routes like so:</p> <pre><code>Rails.application.routes.draw do scope :module =&gt; 'contact' do get "contact", :to =&gt; 'contacts#new' get "contact/send_email", :to =&gt; 'contacts#send_email', :as =&gt; 'send_email' end end </code></pre> <p>Then, in /websites/Engines/contact/app/controllers/contacts_controller.rb, I have:</p> <pre><code>module Contact class ContactsController &lt; ApplicationController # Unloadable marks your class for reloading between requests unloadable def new @contact_form = Contact::Form.new end def send_email @contact_form = Contact::Form.new(params[:contact_form]) if @contact_form.valid? Notifications.contact(@contact_form).deliver redirect_to :back, :notice =&gt; 'Thank you! Your email has been sent.' else render :new end end end end </code></pre> <p>I loaded it up in the client app's console to prove to myself some basics were working and quickly got this load error (which I then confirmed by reproducing the issue in a browser):</p> <pre><code>ruby-1.8.7-p302 &gt; Contact::Form.new =&gt; #&lt;Contact::Form:0x2195b70&gt; ruby-1.8.7-p302 &gt; app.contact_path =&gt; "/contact" ruby-1.8.7-p302 &gt; r = Rails.application.routes; r.recognize_path(app.contact_path) LoadError: Expected /websites/Engines/contact/app/controllers/contacts_controller.rb to define ContactsController </code></pre> <p>And there you have it; /contact gets to the engine's contacts_controller.rb but the fact the controller is inside the module Contact makes it unrecognizable.</p> <p>What am I doing wrong?</p>
 

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