Rails routing error using current page?

I am trying to add some conditional open graph tags to my application using current_page, but I get a routing error:

This is what I get rake routes

product GET    /products/:id(.:format)    {:action=>"show", :controller=>"products"}

And this is in my partial part:

<% if current_page?(:controller => 'products', :action => 'show') %>
...
<% end %>

But I get:

Routing Error

No route matches {:controller=>"products", :action=>"show"}

I tried using productand products, but none of them work. Any thoughts?

+5
source share
1 answer

You must also pass in the identifier:

<% if current_page?(:controller => 'products', :action => 'show', :id => params[:id]) %>

UPDATE:

But, however, this implementation assumes that pages that display this partial have id as a parameter. If they do not, it is best to use a local variable for this.

render :partial => 'blah_blah', :locals => {:id_for_route_verification => params[:id] || 0}

<% if current_page?(:controller => 'products', :action => 'show', :id => id_for_route_verification) %>

, . content_for , current_page?

+5

All Articles