RoutingError when ajax paginate is called from a page whose route is namespaced #247

Closed
ev01ve opened this Issue Jun 20, 2012 · 4 comments

Comments

Projects
None yet
2 participants

ev01ve commented Jun 20, 2012

My project has a notifications menu at the top of the page, and it is present everywhere on the site.

In application_controller.rb I have

@menu_notifications = current_user.notification_relationships.order('seen, created_at DESC').page(params[:menu_notifications_page]).per(10)

and in the view (haml) I have

= paginate @menu_notifications, :param_name => :menu_notifications_page, :params => {:controller => '/pages', :action => 'menu_notifications_page'}, :remote => true

in my routes i have

match 'pages/menu_notifications_page', :to => 'pages#menu_notifications_page'

This works flawlessly from most pages on the site. The only place it breaks is on a page with a namespaced route, which is my devise users/edit route. In my case the route is /users/edit.current_user_name. On this page, I get:

ActionController::RoutingError (No route matches {:action=>"menu_notifications_page", :controller=>"users/pages", :format=>"current_user_name", :menu_notifications_page=>2}):

Somehow, Kaminari sets the controller to "users/pages", even though I clearly specified the controller to be "/pages" in the :params for paginate. If I had set the controller to "pages" this behavior might be understandable, but the leading slash should have caused the controller to have no nesting (this behavior works with url_for). It's behaving as if Kaminari strips the leading slash from the string.

A hack to get this working in the meantime was to add this to my routes:

  match :controller => "users/pages", :action => "menu_notifications_page", :to => 'pages#menu_notifications_page'
Owner

yuki24 commented Dec 12, 2012

It turns out that this is because of Rails' url_for. Try the following on rails console:

params = {:controller => '/pages', :action => 'menu_notifications_page'}
params[:controller] # => "/pages"

YourApp::Application.routes.url_for(params)

params[:controller] # => "pages"

There needs to be some workaround on kaminari-side until Rails 3.2.10 and Rails 4.0 are released.

Owner

yuki24 commented Jan 8, 2013

Rails 3.2.10 only contains a security fix so it doesn't solve this issue. The root cause of this is this line.

Owner

yuki24 commented Jun 29, 2013

FYi, this issue doesn't appear on Rails edge, 4.0.0, 3.2.18 but does appear on 3.1.12 and 3.0.20.

@ghost ghost assigned yuki24 Jun 29, 2013

Owner

yuki24 commented Jul 2, 2013

I'm closing this issue. Please use Rails 4.0.0, 3.2.13 or above to avoid this issue.

@yuki24 yuki24 closed this Jul 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment