to_json在Rails中使用了哪些参数?

时间:2013-02-27 00:16:12

标签: ruby-on-rails

  def show
    email = UserEmail.find_by_key(UserEmail.key_for(UserEmail.new(:publisher_id => @publisher.name, :app_id => @app ? @app.name : 'none', :external_uid => @user.external_uid)))
    respond_to do |format|
      format.xml { render :xml => @user.to_xml(:session => false, :authorized => user_logged_in? || publisher_logged_in? || app_logged_in?, :publisher => @publisher, :email => email || false) }
      format.json { render :json => @user.to_json(:session => false, :authorized => user_logged_in? || publisher_logged_in? || app_logged_in?, :publisher => @publisher, :email => email || false) }
    end
  end

这是我的代码,我特别想了解以下内容:

format.json { render :json => @user.to_json(:session => false, :authorized => user_logged_in? || publisher_logged_in? || app_logged_in?, :publisher => @publisher, :email => email || false) }

1 个答案:

答案 0 :(得分:0)

to_json唯一可以理解的参数是:only:except:methods:include(请查看文档here)。

如果您的to_json使用其他参数,那是因为它(或方法as_json)已在模型中被覆盖。