Posts tagged ‘content’
@content_for_layout
If you create a template file in the app/views/layouts with the same name as a controller, all views used by that controller will use that layout by default.controller/store_controller.rb ::::: consists of method1 & method2def method1
@first_name = “Rajesh”
end
def method2
@last_name = “Kumar”
end
views/store :::::: consists two html method1.rhtml & method2.rhtml
method1.rhtml
<h2>My first name is :: <%= @first_name %> </h2>
method2.rhtml
<h2>My last name is :: <%= @last_name %> </h2>
views/layouts/store.rhtml ::::: same as controller’s name
<html>
<body>
<h4>This is the main template </h4>
<i> Rails automatically sets the variable @content_for_layout to the page specific content- the stuff generated by the view invoked.</i>
<div>
<%= @content_for_layout %>
</div>
</body>
</html>
http:// ………/store/method1
This is the main template
Rails automatically sets the variable @content_for_layout to the page specific content- the stuff generated by the view invoked.
My first name is :: Rajesh
http:// ………/store/method2
This is the main template
Rails automatically sets the variable @content_for_layout to the page specific content- the stuff generated by the view invoked.
My last name is :: Kumar


