Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
ev01ve opened this Issue · 4 comments

2 participants

@ev01ve

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'
@yuki24
Collaborator

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.

@yuki24
Collaborator

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

@yuki24
Collaborator

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.

@yuki24 yuki24 was assigned
@yuki24
Collaborator

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

@yuki24 yuki24 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.