【问题标题】:sunspot solr, rails 3.1.1: Why do my results have the entire db record printed automatically?sunspot solr,rails 3.1.1:为什么我的结果会自动打印整个数据库记录?
【发布时间】:2011-12-01 11:11:18
【问题描述】:

我在为我的 rails 应用程序设置 Sunspot Solr 时执行了标准程序,但是当我打印结果时,我会自动打印整个数据库记录。

这是我的 results.html.erb:

<%= @users.each do |result| %>
    <%= link_to "#{result.first_name}", user_path(result) %>
<% end %>

渲染的视图是:

Test [#<User id: 38, first_name: "Test", last_name: "Test", email: "test@test.com", encrypted_password: "b519f1c58f8f5b9fffa0ada91ac7ca8316ebb8f8cec548404b8...", salt: "7f6287c48f49ac0a55c2cdc00803caaaa463c3b5efb88b57f40...", created_at: "2011-11-28 07:00:32", updated_at: "2011-11-28 07:00:32">

您能告诉我如何摆脱散列而只显示名字吗?

提前致谢

【问题讨论】:

  • 如下所述,您的&lt;%= @users.each… %&gt; 正在打印@users.each 的返回值,即整个@users 数组。如果您从某处的 Sunspot 教程中复制了 &lt;%=,您应该向作者报告,以便他们纠正错误。
  • 不是我自己写的,是我的错。

标签: ruby-on-rails-3 solr sunspot


【解决方案1】:

在&lt;%= @users.each do |result| %&gt;取出=

所以

<% @users.each do |result| %>
    <%= link_to "#{result.first_name}", user_path(result) %>
<% end %>

【讨论】:

  • 如此愚蠢的错误,最糟糕的是没有意识到这一点,哈哈。非常感谢你。问题解决了
猜你喜欢
  • 1970-01-01
  • 2012-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-02
  • 2015-02-16
相关资源
最近更新 更多