ruby-on-rails - 显示来自 Rails/Neo4j 的哈希值

标签 ruby-on-rails neo4j

我正在从 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_nameproduct_name= 方法之类的内容,用于设置持久属性。

对于迁移,如果您已经设置了 ActiveRecord 模型,则应该查看此项目:

https://github.com/neo4jrb/neo4apis-activerecord

它不需要 ActiveRecord 模型,但它们使导入更加清晰。您仍然需要像我上面建议的那样设置 Neo4j 模型。

我是 neo4apis-activerecordneo4j/neo4j-core gems 的维护者之一,很高兴回答任何问题其他问题可以在此处或 Gitter 上找到

关于ruby-on-rails - 显示来自 Rails/Neo4j 的哈希值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29749357/

相关文章:

ruby-on-rails - 将 ActiveRecord 数组序列化属性转换为字符串

python - 以下模型与 django neomodel

ruby-on-rails - 在 Rails 中创建同名表单元素时的非唯一 ID

ruby-on-rails - 我通过 Rails 模型调用 "undefined method",但通过 Rails 控制台调用时效果很好

css - RoR SCSS/CSS 功能失效

ruby-on-rails - ruby rails : provide vs content_for

scala - Neo4j 中的多线程节点创建

mysql - 结合图形数据库和 RDBMS

java - 在 neo4j [JAVA] 中发送查询

java - neo4j 2.0未创建节点但运行成功