1

As we all know, in ruby on rails, all views extends from application/application.html.erb, most of the time this is great, such as the application.html.erb as follow:

<html>
<head></head>

<body>

<%= render 'layouts/header' %>
<%= yield %>

</body>
</html>

I do not need the write the same code in every view again, but sometimes, just on view is special, this view is different from the view, such as I do not want to add <%= render 'layouts/header' %> in this view.

Maybe a parameter will just help me in this situation, but I want to know if any view is able to not extend from application/application.html.erb?

1

1 Answer 1

4

Views don't 'extend from' application.html.erb, they use it as a default layout. You can change it, of course, using layout method in controller (or layout option in render method), like this:

# this changes the default layout in every views of `AdminController` (and all other controllers that inherit from `AdminController`):
class AdminController < ApplicationController
  layout :admin
  # ...
end
# this changes the layout of specific action:
class SomethingController < ApplicationController
  # ...
  def some_action
    # ...
    render layout: :some_layout
  end
end

Here's the reference: http://guides.rubyonrails.org/layouts_and_rendering.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.