Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Nicolas Brousse asked in Rails
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!
Reply
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.
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.