简体   繁体   English

searchlogic-搜索attr_accessor

[英]searchlogic - searching for attr_accessor

I have a table symbols which contains columns: id and symbol_name , where id is the primary key of that table 我有一个表symbols ,其中包含列: id and symbol_name ,其中id是该表的主键

In my Symbol model, I have 在我的Symbol模型中,

class Symbol < ActiveRecord::Base

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

end

On my index.html.erb page, users can search for symbols with id 777 by entering "EMI:777" in the search textfield. 在我的index.html.erb页面上,用户可以通过在搜索文本字段中输入“ EMI:777”来搜索ID为777的符号。

I am using searchlogic for searching. 我正在使用searchlogic进行搜索。

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

When i use 'symbol_id' in the search form , i get the following error message: 当我在搜索表单中使用'symbol_id'时,出现以下错误消息:

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

Any suggestion is most appreciated 任何建议都非常感谢

According to this post it looks like you will want to do a scope based on the virtual attribute: 根据这篇文章 ,您似乎想要基于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

I not sure that the scope is correct so you may need to dig into that a bit based on your model, controller, etc. 我不确定scope是否正确,因此您可能需要根据模型,控制器等进行深入研究。

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

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