【问题标题】:Json result with model and string value in rails带有模型和字符串值的Json结果在rails中
【发布时间】:2012-02-04 13:15:15
【问题描述】:

我试图在 json 中返回一个活动记录模型和一个字符串值,但不能这样做

这是我的控制器/动作

 def index
    @accounts = Account.search(params[:search_login])
    respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @accounts, :miles => "23"}
    end
end

这里是 Ajax 调用

函数 GetMiles() { $.ajax({url: "/accounts?" + "search_login=" + $('#account_number').val(), 数据类型:“json”, 成功:函数(数据){ 警报(数据.英里) 响应($.map(data.acc,函数(item1){ 警报(item.account_number) } }); }

但无法获得里程价值以及任何模型财产价值,请帮助

【问题讨论】:

    标签: ruby-on-rails-3


    【解决方案1】:

    好的,我在这里找到了解决方案

    responding with multiple JSON renders. (Ruby/Rails)

    感谢堆栈溢出

    【讨论】:

      猜你喜欢
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 2020-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-29
      • 2022-01-04
      相关资源
      最近更新 更多