【问题标题】:Rails Elastics Search Result content URL errorRails Elastics 搜索结果内容 URL 错误
【发布时间】:2015-11-29 11:19:54
【问题描述】:

我只是在我的 Rails 应用程序中尝试使用 Elastic Search 替换现有的搜索功能。一切正常,但我得到了http://localhost:3000/contents/video/%23%3CElasticsearch::Model::Response::Result:0x007fe24e118f40%3E url。

在 content.rb 中

def to_param
        "#{id}/#{title.parameterize}.html"
        #"#{id}-#{title.downcase.slice(0..30).gsub(/[^a-z0-9]+/i, '-')}.html"
    end

在搜索中

  def search 
    if params[:q].nil?
      @indexs = []
    else
      @indexs = Content.search params[:q]
    end 

在视图中

<% @indexs.each do |f|%>
<%= link_to((truncate f.title, length: 60), {:controller => "contents", :action => "weblinks", :id => f.to_param}, target: "_blank") %>
<% end %>

它适用于默认列表页面,但它的 URL 在搜索结果页面中生成错误。请帮忙,以及如何用 weblinks_path(:format) 路由替换{:controller =&gt; "contents", :action =&gt; "weblinks", :id =&gt; f.to_param}

【问题讨论】:

    标签: ruby-on-rails ruby elasticsearch routes


    【解决方案1】:

    我假设你使用elasticsearch gem,如果是这样你应该使用记录来获取 ActiveRecord 模型@indexs.records

    【讨论】:

    • 能否请您说的更清楚些。我无法理解你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多