开发者

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开发者_如何学Python 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) %>


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]


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜