One Two Three
One Two Three

Reputation: 23497

create new page (not having the layout specified in /app/layouts/* files) in rails

Most of my view files have the same layouts, hence it was reasonable to define layouts/application.html.haml (and other header, footer files).

But now I need to create a page that does NOT have any of those styling. In fact, I just want a plain page with a header.

How do I do that?

Upvotes: 0

Views: 43

Answers (2)

boulder
boulder

Reputation: 3266

I think you're after. In your controller, assuming your action is called myaction

    def myaction
      # do here whatever you need to do and then
      render :layout => false
    end

See options for render in Rails Guide: layouts and redendering

Upvotes: 1

Jesper
Jesper

Reputation: 4555

You can specify the layout in the controller like so:

class ThingsController < ApplicationController
  layout "some_layout"

  # rest of the controller
end

This would look for app/views/layouts/some_layout.html.erb

You can also use a method to choose the layout:

class ThingsController < ApplicationController
  layout :choose_layout

  def choose_layout
    current_user.cat? ? "cat" : "dog"
  end
  # rest of the controller
end

Upvotes: 1

Related Questions