我使用meta_search如下:
# app/controllers/articles_controller.rb
def index
@search = Article.search(params[:search])
@articles = @search.all
end
# app/views/articles/index.html.erb
<%= form_for @search, :url => articles_path, :html => {:method => :get} do |f| %>
<%= f.text_field :my_very_long_attribute_name_contains %><br />
<%= f.submit %>
<% end %>
通过允许搜索“my_very_long_attribute_name”属性,这可以按预期工作。
问题是,?search[my_very_long_attribute_name_contains]
出现在查询字符串中。将较短名称映射到此属性的最佳方法是什么?IE?search[mvlan_contains]
这不仅仅是想让长属性名称更短的情况,而且我还需要伪装一些潜在敏感属性的名称以进行搜索。
我看过alias_attribute
,但无法让 meta_search 识别属性别名。
我欢迎任何建议。