【发布时间】: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 => "contents", :action => "weblinks", :id => f.to_param}
【问题讨论】:
标签: ruby-on-rails ruby elasticsearch routes