Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ruby中的映射字段值_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails ruby中的映射字段值

Ruby on rails ruby中的映射字段值,ruby-on-rails,ruby,Ruby On Rails,Ruby,我有这样的类数组: @types = Type.where("TYP_MOD_ID = ?", params[:mod_id]) 有我有现场类型的KV燃料ID,编号是。。。。 但是我如何通过map方法改变这个值呢? 我试过这样的方法: def get_types_for_mod2 @types = Type.where("TYP_MOD_ID = ?", params[:mod_id]) @types.map { |e| e.TYP_KV_FUEL_DES_ID = get_v

我有这样的类数组:

@types = Type.where("TYP_MOD_ID = ?", params[:mod_id])
有我有现场类型的KV燃料ID,编号是。。。。 但是我如何通过map方法改变这个值呢? 我试过这样的方法:

def get_types_for_mod2
    @types = Type.where("TYP_MOD_ID = ?", params[:mod_id])
    @types.map { |e| e.TYP_KV_FUEL_DES_ID = get_via_designation(e.TYP_KV_FUEL_DES_ID) }
    respond_to do |format|
      format.json { render :json => @types}
    end
  end
def get_via_designation(id)
    designation = Designation.find_by_DES_ID(id)
    destext = DesText.find_by_TEX_ID(designation.DES_TEX_ID)
    destext.TEX_TEXT
  end
那么我怎样才能改变e.TYP_KV_FUEL_DES_ID的值呢

upd1: 我不需要做任何事情!只是为了json,我获取数据并更改视图字段!没有db

@types = Type.where("TYP_MOD_ID = ?", params[:mod_id]).map do |type| 
  type.TYP_KV_FUEL_DES_ID = get_via_designation(type.TYP_KV_FUEL_DES_ID)
  type
end
在这里,我们将映射查询
类型的结果。其中(“TYP_MOD_ID=?”,params[:MOD_ID])
并将
TYP_KV_FUEL_DES_ID
设置为从
通过指定获取_返回的值


更新:添加了映射块将返回“type”

似乎您希望在此处使用
每个
,而不是
映射
映射
返回一个变换后的数组,其中
每个
只是迭代,对于此处这样的就地更改非常有用。\@sergioturentsev with each也不好。。。。。举例说明please@tadman如何解决?为什么不直接使用inject?比如:
@types.inject([]){types,el | el.attr=new | attr;types是的……你确定它将映射到什么吗?@SergioTulentsev更新了,它不会只返回新的“TYP|u KV_FUEL_DES_ID”。谢谢。@ValidsAzaramis-你看过这个答案了吗?