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=>"show"}
I’ve tried using product and products but neither seems to work. Any thoughts?
You should pass the id as well:
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.
and in the partial use the new local variable
I know this is kinda hacky. But, in the first place, you should consider using
content_forto render content inside partial conditionally rather than going bycurrent_page?approach