- Implement a Rails Engine with
engine_name
defined - Expect host application to use
mount
if they want to inherit routes
Example:
module Hydra
module Collections
class Engine < ::Rails::Engine
engine_name "collections"
end
end
end
Expect host application to use mount
if they want to inherit routes from your engine
# config/routes.rb in the host application
Internal::Application.routes.draw do
mount Hydra::Collections::Engine => '/'
root :to => "catalog#index"
...
end
Example:
<%= button_to label, collections.new_collection_path, :method=>:get %>
The form_for
helper generates the form's @action url for you. In order to ensure that the form knows how to generate that path, tell it to use the engine by passing an Array rather than just the instance.
Example:
<%= form_for([collections, @collection])` do %>
In your spec_helper.rb, set your controller tests to use the routes from the current engine
Example
# spec/spec_helper.rb
RSpec.configure do |config|
...
config.before(:each, :type=>"controller") { @routes = Hydra::Collections::Engine.routes }
end
If you've set the routes in your spec_helper using the method above, then tests will only have access to routes defined by the engine you're testing. If you need to reference routes/paths that come from other dependencies, use Rails.application.routes.url_helpers
Example:
response.should redirect_to(Rails.application.routes.url_helpers.catalog_index_path("collection[]"=>assigns[:collection].id))