Rails current_page? versus controller.controller_name

坚强是说给别人听的谎言 提交于 2019-11-28 17:04:13

current_page?(root_path) works fine.

But I can't make it work with :controller and :action

It seems the helper expects a string, so:

current_page?(url_for(:controller => 'pages', :action => 'main')) 

works fine too.

Weird contradiction with the doc.

I had this issue when I had 2 routes that were very similar. Check this out:

match '/galleries/sales' => 'galleries#sales', :as => 'gallery_sales'
match '/galleries/sales/:id' => 'galleries#sales', :as => 'gallery_category_sales'

My controller action handled the output depending on params, and I originally did this b/c I didn't want duplication.

When I did:

current_page?(:controller => 'galleries', :action => 'sales', :id => id)

It didn't return true when it should have, so I created a different route and action and it worked fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!