我正在使用 rails-jquery-autocomplete 填写cabinet_name
如下表格:
<%= autocomplete_field_tag :cabinet_name, '', cabinets_autocomplete_cabinet_name_path %>
连同其他数据,以下是传递给设备控制器的参数:
{"utf8"=>"✓",
"authenticity_token"=>"/0yFGrlBy0y+2ksTkQN50Dmfpw7ZWBKsO2zswAigJZI=",
"device"=>{"name"=>"Test dropdown",
"device_model_id"=>"621",
"device_unit_count"=>"1",
"position"=>"1",
"row_id"=>"1"},
"cabinet_name"=>"0055-COMM-ANNEX-C3",
"commit"=>"Create Device"}
如您所见,哈希中肯定有一个cabinet_name
正在传递。device
这是 中的代码devices_controller
:
def create
if params[:cabinet_name]
@cabinet = Cabinet.where("name LIKE ? ", params[:cabinet_name])
else
@cabinet = Cabinet.find(params[:device][:cabinet_id])
end
...
@device.row_id = @cabinet.row_id
这是根据命令行输出运行的查询,请注意:
←[1m←[35mCabinet Load (2.9ms)←[0m SELECT `cabinets`.* FROM `cabinets` WHERE (
name LIKE '0055-COMM-ANNEX-C3' )
这是我运行的手动查询和结果,显示了一个柜记录的结果:
mysql> select `cabinets`.* from `cabinets` where name like '0055-COMM-ANNEX-C3'
---------------+
| id | name | row_id | data_center_id | cabinet_type_id | creat
d_at | updated_at | row_name | cabinet_name | capacity_used |
not_cabinet | grid_location_name | grid_location_id | is_rack | alias_name
| room_id | mark_review | mark_validated | mark_audit | last_audit_note | ma
k_deleted | purpose | total_power_kpm | total_max_power_kpm | total_heat_btu |
otal_max_heat_btu | total_heat_kpm | total_max_heat_kpm | total_spec_ratings |
ean_efficiency |
------------------+----------------+--------------------+--------------------+-
---------------+
| 1389 | 0055-COMM-ANNEX-C3 | NULL | 3 | 1 | 2012-
1-05 21:55:23 | 2012-11-21 16:21:34 | C3 | C3 | 2 |
NULL | C3 | 2287 | 0 | 0055-COMM-ANNEX
C3 | 4 | NULL | NULL | NULL | NULL |
NULL | NULL | 42 | 64 | 200 |
280 | 8 | 10 | 0 |
NULL |
------------------+----------------+--------------------+--------------------+-
---------------+
1 row in set (0.00 sec)
这是浏览器抛出的错误,说明现在选择了内阁:
undefined method `row_id' for #<ActiveRecord::Relation:0x5845368>
如果您了解问题,请提供一些帮助。谢谢。