2010-12-08 61 views
0

名字我使用meta_search如下:的Rails 3:別名屬性在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]出現在查詢字符串中。將較短的名稱映射到此屬性的最佳方式是什麼?即?search[mvlan_contains]

這不僅僅是想縮短長屬性名稱的情況,而且我還需要僞裝某些潛在敏感屬性的名稱以用於搜索。

我看過alias_attribute,但無法通過meta_search識別屬性別名。

我歡迎任何建議。

+1

自己並沒有使用它,但看看自述文件中的「訪問自定義搜索方法」部分 - https://github.com/ernie/meta_search – 2010-12-08 18:37:45

+0

謝謝。雖然這很有用,但它不能使我爲我的屬性創建別名。 – gjb 2010-12-08 23:57:07

回答

1

你可以像rspeicher建議的那樣做。自定義搜索方法將顯示在您的參數列表中。

回覆:您的屬性中的敏感信息,雖然...如果有人知道您的屬性名稱在視圖中對您的應用程序構成潛在的問題,我會認真考慮在您的模型和控制器層中採取了哪些安全措施。