Acrux
Acrux

Reputation: 406

How to check current page if at show action without passing id

Is there a way to use current_page? to check if the user is at posts/x where x is any number? I am trying to use facebook's OG meta tags but I need to only show them if the user is at the show action of my Posts Controller.

What I currently have (yields an error because of the lack of id):

<%if current_page?(controller:"posts",action:"show")%>
<meta property="og:title" content=" <%= @post.title %>" />
<meta property="og:description" content="<%= @post.body.html_safe %>" />
<meta property="og:image" content="<%=URI.join(request.url,@post.news_image.url) %>" />
<%end%>

I plan to put this in the Header part of my application.html.erb, hence the need to find a way to determine if the current page is the show action. Any ideas on how I can use current_page or any other solutions?

Upvotes: 3

Views: 1830

Answers (1)

Sebasti&#225;n Palma
Sebasti&#225;n Palma

Reputation: 33460

I don't know how's your current_page? method defined, but you can easily achieve it just checking the params controller and action, like:

<% if params[:controller] == 'posts' && params[:action] == 'show' %>
  <meta property="og:title" content="<%= @posts.id %>" /> <!-- id as example -->
<% end %>

Upvotes: 5

Related Questions