Rails 怎样为含有 respond_to 的 action 指定 layout?

bryanwong · January 29, 2012 · Last by lgn21st replied at February 04, 2012 · 3690 hits

代码示例:

def show
  @post = Post.find(params[:id])
  respond_to do |format|
      format.html
      format.json
  end
end

show 会默认调用 application.html.erb layout。怎样禁用这个 layout 呢?或者指定其他 layout?

谢谢!

找到了一个方法:

def show
  @post = Post.find(params[:id])
  respond_to do |format|
    format.html  {render :layout => false}
    format.json
  end
end

#1 楼 @bryanwong 楼主用 markdown 语法格式化一下自己的主题贴和回复贴吧。

You need to Sign in before reply, if you don't have an account, please Sign up first.