Msencenb
Msencenb

Reputation: 5104

Double Render with layout and partials

Ok so I have a show method that tries to render a layout and the show view renders a couple partials but I am getting a double render error in rails. How do I get it to render the layout and the partials? Note that it renders just fine with the default layout.

Here is my controller action

def show
  @site = Site.find_by_subdomain!(request.subdomain)
  @page = @site.pages.find_by_name('index')

  render :layout => "layouts/mobile"
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @site }
  end
end

And my view simply looks like this:

<%= render(:partial => "page", :object => @page) %>

Upvotes: 1

Views: 910

Answers (2)

mkro
mkro

Reputation: 1892

Not sure why you call render in your action at that exact place where you call it. In short: You shouldn't need to do it there. If you do it, rails will try to render again when the method returns control, so you either have to return from the method after calling render or not call it in the method.

Upvotes: 0

Msencenb
Msencenb

Reputation: 5104

Ok figured it out. Sorry for the post but I'll answer it in case someone else has the problem. Basically at the top of my controller file I just needed this line:

layout "layouts/mobile", :only => [:show]

Upvotes: 2

Related Questions