My action has:
我的行动有:
render json: {
"user" : @user,
"blah" : @blah
}
In dev mode, ie. Rails.env.development? is true I want to render the json using pretty print.
在开发模式中,即。 Rails.env.development?是的,我想使用漂亮的打印渲染json。
How can I do this?
我怎样才能做到这一点?
1 个解决方案
#1
1
if Rails.env.development?
render text: JSON.pretty_generate('user' => @user.attributes)
else
render json: { 'user' => @user.attributes }
end
#1
1
if Rails.env.development?
render text: JSON.pretty_generate('user' => @user.attributes)
else
render json: { 'user' => @user.attributes }
end