我正在从 Postgres 迁移到 Neo4j,并且我尝试显示 Neo4j 查询的结果是部分结果。
home_controller.rb
def index
@products = Product.as(:p).where(featured: True).limit(12).pluck(:p)
respond_with(@products)
end
index.html.erb
<div class="row">
<div id="products">
<%= render partial: "/products/product_display", collection: @products, as: :product, locals: { product_class: "col-lg-4 col-md-4 col-sm-4 product" } %>
</div>
</div>
_product_display.html.erb
:
<div class="product-title">
<h5><%= link_to product.product_name, product_detail_path(product) %></h5>
</div>
:
我似乎遇到的问题是它返回以下内容:
[#<Product>, #<Product>, #<Product>, #<Product>, #<Product>, #<Product>, #<Product>, #<Product>, #<Product>, #<Product>, #<Product>, #<Product>]
我得到:
undefined method `product_name' for #<Product>
我确信这只是掌握 Rails 基本理解的一部分,但使用 Postgres 就可以了。
我是新手,希望得到一些帮助。
最佳答案
我猜您没有为 product_name
分配属性。由于 Neo4j 是无模式的,因此它无法像 ActiveRecord 那样从数据库中读取列列表。如果你这样做会怎样?
class Product
include Neo4j::ActiveNode
property :product_name
end
property
方法设置诸如 product_name
和 product_name=
方法之类的内容,用于设置持久属性。
对于迁移,如果您已经设置了 ActiveRecord 模型,则应该查看此项目:
https://github.com/neo4jrb/neo4apis-activerecord
它不需要 ActiveRecord 模型,但它们使导入更加清晰。您仍然需要像我上面建议的那样设置 Neo4j 模型。
我是 neo4apis-activerecord
和 neo4j
/neo4j-core
gems 的维护者之一,很高兴回答任何问题其他问题可以在此处或 Gitter 上找到
关于ruby-on-rails - 显示来自 Rails/Neo4j 的哈希值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29749357/