最初のエンジンを作成しました。次のような新しいルートがいくつか追加されます。
Rails.application.routes.draw do
scope :module => 'contact' do
get "contact", :to => 'contacts#new'
get "contact/send_email", :to => 'contacts#send_email', :as => 'send_email'
end
end
次に、/websites/Engines/contact/app/controllers/contacts_controller.rb に次のように記述します。
module Contact
class ContactsController < 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 => 'Thank you! Your email has been sent.'
else
render :new
end
end
end
end
クライアントアプリのコンソールにロードして、いくつかの基本が機能していることを証明したところ、すぐにこのロードエラーが発生しました(ブラウザで問題を再現して確認しました):
ruby-1.8.7-p302 > Contact::Form.new
=> #<Contact::Form:0x2195b70>
ruby-1.8.7-p302 > app.contact_path
=> "/contact"
ruby-1.8.7-p302 > r = Rails.application.routes; r.recognize_path(app.contact_path)
LoadError: Expected /websites/Engines/contact/app/controllers/contacts_controller.rb to define ContactsController
そして、あなたはそれを持っています。/contact はエンジンのcontacts_controller.rbに到達しますが、コントローラがモジュール Contact 内にあるという事実により認識できなくなります。
私は何を間違っていますか?