Rails Elastics搜索结果内容URL错误

时间:2015-11-29 11:19:55

标签: ruby-on-rails ruby elasticsearch routes

我只是在我的Rails应用程序中尝试弹性搜索,取代现有的搜索功能。一切都很顺利,但我得到http://localhost:3000/contents/video/%23%3CElasticsearch::Model::Response::Result:0x007fe24e118f40%3E网址。

in 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}

1 个答案:

答案 0 :(得分:0)

我假设您使用class SomeClass{ public static void main(String[] args) { ToBeImplemented someImplementation; //now you can pick an implementation, based on user input for example if (userInput == something) someImplementation = new ImplementationA(); else someImplementation = new ImplementationB(); //do some staff //Regardless of the user input, main method only knows about the //abstract "ToBeImplemented", and so calls the .doThis() method of it //and the right method gets called based on the user input. someImplementaion.doThis(); //at That } } gem,如果是这样,您应该使用记录来获取ActiveRecord模型elasticsearch