You can add your title for views in two ways.for adding title in views you have to follow these steps:
1-> add <title><%= yield(:title) %></title> inside the header of your layout.
2-> now you can add your title inside your view.there are following ways to do that:
a-> use this line in your view:
<%= content_for(:title, "Title for specific page") %>
b-> use helper method:
def title(page_title)
content_for :title, page_title.to_s
end
c-> if you want to write title for view in controller then add this method inside your application_controller.
def view_context
super.tap do |view|
view.content_for :title, "your title"
end
end
if you want to add title according to your controller and action names pair then:
def view_context
super.tap do |view|
view.content_for :title, "#{controller_name}_#{action_name}"
end
end
1-> add <title><%= yield(:title) %></title> inside the header of your layout.
2-> now you can add your title inside your view.there are following ways to do that:
a-> use this line in your view:
<%= content_for(:title, "Title for specific page") %>
b-> use helper method:
- add a helper method in application_helper
def title(page_title)
content_for :title, page_title.to_s
end
- inside your view:
c-> if you want to write title for view in controller then add this method inside your application_controller.
def view_context
super.tap do |view|
view.content_for :title, "your title"
end
end
if you want to add title according to your controller and action names pair then:
def view_context
super.tap do |view|
view.content_for :title, "#{controller_name}_#{action_name}"
end
end