Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added prefix option to router. #58

Merged
merged 2 commits into from
Jun 10, 2015
Merged

Conversation

AlfonsoUceda
Copy link
Contributor

Problem

There is a problem in lotusrb gem generating correct routes when the apps are mounted inside lotus container:

class AdminApp  < Lotus::Application
  configure do
    routes do
      get '/home', to 'home#index', as: :home
    end
  end
end
Lotus::Container.configure do
  mount AdminApp, at: '/admin'
  mount App, at: '/'
end
AdminApp::Routes.path(:home) # => '/home' <- WRONG
# should be
AdminApp::Routes.path(:home) # => '/admin/home' <- GOOD

Solution

This PR add prefix option to router, later we can pass in lotusrb the at: option as prefix for the router.

router = Lotus::Router.new(prefix: '/admin') do
  get '/home', to: 'home#index', as: ':home'
end

router.path(:home) # => '/admin/home'

@@ -341,7 +341,7 @@ def defined?
# # It will map to Flowers::Index.new, which is the
# # Lotus::Controller convention.
def get(path, options = {}, &blk)
@router.get(path, options, &blk)
@router.prefixed_namespace.get(path, options, &blk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlfonsoUceda This leaks Lotus::Routing::HttpRouter details to the higher level. That low level class should hide this detail. Lotus::Router#get should remain untouched, while Lotus::Routing::HttpRouter#get should handle this.

@jodosha jodosha self-assigned this Jun 9, 2015
@jodosha jodosha added this to the v0.4.1 milestone Jun 9, 2015
@jodosha
Copy link
Member

jodosha commented Jun 10, 2015

@AlfonsoUceda This looks really, really clean now 👏

@jodosha jodosha merged commit 36bdfa0 into hanami:master Jun 10, 2015
jodosha added a commit that referenced this pull request Jun 10, 2015
@AlfonsoUceda AlfonsoUceda deleted the prefix_router branch June 17, 2015 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants