Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

I18n access ".title" key with view context in layout

Rails • Asked by Nicolas Brousse
Hi!

I try to create a small view helper to manage content for `<title>`.

module ApplicationHelper
  def page_title(options = {})
    app_name = Rails.application.class.to_s.split("::").first

    key = "#{controller_name}.#{action_name}.title"
    title = content_for(:page_title) || t(key, default: "")

    [app_name, title].join(" : ")
  end
end

I use high_voltage gem. If I do `t(".title")` it attempt to call `en.pages.about.title` and in my helper it attempt to call `en.pages.show.title`.

I try to found a method to use instead `action_name` to get `about` instead `show` but I didn't found. 
I looked the rails code and found this method is used, but I can't access to the `@virtual_path`.

I think there is a proper way to do this, but I didn't found for now.  
Does somebody has any idea?

Thanks!

In fact `@virtual_path` is accessible inside `ApplicationHelper`. But it returns the path for the layout.

So finally what I would like, is to know the view name of the view called in the action controller.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.