Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix url helpers on mountable engines #186

Closed
wants to merge 1 commit into from

5 participants

@marcelloma

This should fix issue #183...

Fixed some silly stuff from the other pull request.

@knewter

+1, can this get merged?

@rahult

+1, for this to be merged

@rafaelfranca
Collaborator

This pull request is broken with the Rails 3.2

@joelmoss joelmoss closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 8, 2011
  1. @marcelloma
This page is out of date. Refresh to see the latest.
View
8 lib/inherited_resources/class_methods.rb
@@ -259,7 +259,7 @@ def custom_actions(options)
# Makes sense when using rails 3.1 mass assignment conventions
def with_role(role)
self.resources_configuration[:self][:role] = role.try(:to_sym)
- end
+ end
private
@@ -338,6 +338,12 @@ def initialize_resources_class_accessors! #:nodoc:
# Deal with namespaced controllers
namespaces = self.controller_path.split('/')[0..-2]
+
+ # Remove namespace if its a mountable engine
+ namespaces.delete_if do |namespace|
+ namespace.camelize.constantize.respond_to? :_railtie
+ end
+
config[:route_prefix] = namespaces.join('_') unless namespaces.empty?
# Deal with default request parameters in namespaced controllers, e.g.
View
22 test/class_methods_test.rb
@@ -23,6 +23,18 @@ class DeansController < InheritedResources::Base
belongs_to :school
end
+module MyEngine
+ class Engine < Rails::Engine
+ isolate_namespace MyEngine
+ end
+
+ class PeopleController < InheritedResources::Base; end
+end
+
+module MyNamespace
+ class PeopleController < InheritedResources::Base; end
+end
+
class ActionsClassMethodTest < ActionController::TestCase
tests BooksController
@@ -132,3 +144,13 @@ def test_url_helpers_are_recreated_just_once_when_belongs_to_is_called_with_mult
DeansController.send(:parents_symbols=, [:school])
end
end
+
+class MountableEngineTest < ActiveSupport::TestCase
+ def test_route_prefix_do_not_include_engine_name
+ assert_nil MyEngine::PeopleController.send(:resources_configuration)[:self][:route_prefix]
+ end
+
+ def test_route_prefix_present_when_parent_module_is_not_a_engine
+ assert_equal 'my_namespace', MyNamespace::PeopleController.send(:resources_configuration)[:self][:route_prefix]
+ end
+end
Something went wrong with that request. Please try again.