我如何指定 ":layout =>假"在 Rails 的 response_with 中? [英] How do I specify ":layout => false" in Rails' respond_with?
本文介绍了我如何指定 ":layout =>假"在 Rails 的 response_with 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个设置:
class UsersController < InheritedResources::Base
respond_to :html, :js, :xml, :json
def index
@users = User.all
respond_with(@users)
end
end
现在我正在尝试这样做,如果 params[:format] =~/(js|json)/
, render :layout =>假, :text =>@users.to_json
.我如何使用 respond_with
或 respond_to
和inherited_resources 做到这一点?
Now I am trying to make it so, if params[:format] =~ /(js|json)/
, render :layout => false, :text => @users.to_json
. How do I do that with respond_with
or respond_to
and inherited_resources?
推荐答案
类似:
def index
@users = User.all
respond_with @users do |format|
format.json { render :layout => false, :text => @users.to_json }
end
end
这篇关于我如何指定 ":layout =>假"在 Rails 的 response_with 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文