0

升级到 Rails 2.3.11 后,我不能再使用 SlickGrid 创建我们所谓的数据集。如果单击切换图标来创建数据集,我会得到以下堆栈跟踪:

NoMethodError (undefined method `name' for {"name"=>"Data Set 1", "values"=>["", ""]}:Hash):
  lib/slick_data.rb:99:in `to_data_json'
  lib/slick_data.rb:97:in `map'
  lib/slick_data.rb:97:in `to_data_json'
  app/controllers/data_sets_controller.rb:11:in `index'
  haml (3.0.22) lib/sass/plugin/rack.rb:41:in `call'
  airbrake (3.0.4) lib/airbrake/rack.rb:27:in `call'
  airbrake (3.0.4) lib/airbrake/user_informer.rb:12:in `call'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:95:in `start'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:92:in `each'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:92:in `start'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:23:in `start'
  /Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:82:in `start'

这是 slick_data.rb 中的“to_data_json”代码:

def to_data_json
  new_data = sanitized_data.map do |d|
    h = {}
    h['data_set_name'] = d.name
    j = 1
    d['values'].each do |v|
      h["var_#{j}"] = v
      j += 1
    end
    h
  end
  ActiveSupport::JSON.encode(new_data)
end

这是 data_sets_controller.rb 中“索引”的代码:

def index # Ajax
  @scenario = Scenario.find(params[:scenario_id])
  sd = SlickData.new(@scenario.data_sets)
  render :json => {
    :html    => render_to_string(:layout => false, 
                                 :template => 'data_sets/index.html.erb', 
                                 :object => @scenario),
    :id      => @scenario.id,
    :data    => sd.to_data_json,
    :columns => sd.to_col_json,
  }
end

我可能需要升级我的 json gem 吗?我正在使用 1.4.6。或者也许我需要升级我的 SlickGrid 版本?我使用的是 1.4.3 版。谢谢。

4

1 回答 1

0

没关系,我只需要更改d.named['name']lib/slick_data.rb 即可修复错误。我想知道为什么这在 Rails 2.3.5 之前也有效?

于 2012-07-17T19:03:10.023 回答