【问题标题】:Displaying Hashed values from Rails/Neo4j从 Rails/Neo4j 显示哈希值
【发布时间】:2015-06-27 06:22:09
【问题描述】:

我正在从 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 没问题。

我是新手,希望能得到一些帮助。

【问题讨论】:

    标签: ruby-on-rails neo4j


    【解决方案1】:

    我猜您没有分配给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 上回答任何其他问题

    【讨论】:

    • 你的明星!我知道这将是一件非常容易的事情。我有时需要踢! :) 谢谢
    猜你喜欢
    • 2017-07-09
    • 1970-01-01
    • 2015-09-22
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多