繁体   English   中英

searchlogic-搜索attr_accessor

[英]searchlogic - searching for attr_accessor

我有一个表symbols ,其中包含列: id and symbol_name ,其中id是该表的主键

在我的Symbol模型中,

class Symbol < ActiveRecord::Base

def symbol_id
"EMI:#{self.id}"
end

end

在我的index.html.erb页面上,用户可以通过在搜索文本字段中输入“ EMI:777”来搜索ID为777的符号。

我正在使用searchlogic进行搜索。

<% form_for @search do |f| %>
    Search:
    <%= f.text_field :symbol_id_or_symbol_name_like %>
    <%= f.submit "Search" %>
<% end %>

当我在搜索表单中使用'symbol_id'时,出现以下错误消息:

The condition 'symbol_id' is not a valid condition, we could not find any scopes that match this.

任何建议都非常感谢

根据这篇文章 ,您似乎想要基于virtual属性进行范围

class Symbol < ActiveRecord::Base
  attr_accessor :symbol_id
  scope :symbol_id_search, where("symbol_id = ?", symbol_id)  

  def initialize
    @symbol_id = "EMI:#{self.id}"
  end

end

我不确定scope是否正确,因此您可能需要根据模型,控制器等进行深入研究。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM