Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.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 Rails最佳实践-返回AR查询+通过控制器查看的任意数据?_Ruby On Rails - Fatal编程技术网

Ruby on rails Rails最佳实践-返回AR查询+通过控制器查看的任意数据?

Ruby on rails Rails最佳实践-返回AR查询+通过控制器查看的任意数据?,ruby-on-rails,Ruby On Rails,我想知道从Rails控制器向视图传递查询+任意数据的最佳实践是什么 # simple query product = Product.find(id) # some data to append to our instance var and send to view extra_data = "some arbitrary string data" @view = Hash.new @view["product"]=product.attributes @view["product"]["e

我想知道从Rails控制器向视图传递查询+任意数据的最佳实践是什么

# simple query
product = Product.find(id)
# some data to append to our instance var and send to view
extra_data = "some arbitrary string data"

@view = Hash.new
@view["product"]=product.attributes
@view["product"]["extra_data"]=extra_data
有更好/更干净/更短的方法吗?也许合并散列

谢谢