I'm trying to add some conditional open graph tags to my app, using current_page
, but I'm getting a routing error:
This is what I get on rake routes
product GET /products/:id(.:format) {:action=>"show", :controller=>"products"}
And this is in my partial:
<% if current_page?(:controller => 'products', :action => 'show') %>
...
<% end %>
But I get:
Routing Error
No route matches {:controller=>"products", :action=>开发者_如何学Python"show"}
I've tried using product
and products
but neither seems to work. Any thoughts?
You should pass the id as well:
<% if current_page?(:controller => 'products', :action => 'show', :id => params[:id]) %>
UPDATE:
But, however, this implementation assumes that the pages that render this partial have id as a param. If they do not, it's better to use a local variable for that.
render :partial => 'blah_blah', :locals => {:id_for_route_verification => params[:id] || 0}
and in the partial use the new local variable
<% if current_page?(:controller => 'products', :action => 'show', :id => id_for_route_verification) %>
I know this is kinda hacky. But, in the first place, you should consider using content_for
to render content inside partial conditionally rather than going by current_page?
approach
精彩评论