Rails 3:meta_search 中的别名属性名称
我使用 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 识别属性别名。
我欢迎任何建议。
I am using meta_search as follows:
# 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 %>
This works as expected, by allowing the 'my_very_long_attribute_name' attribute to be searched.
The problem is, ?search[my_very_long_attribute_name_contains]
appears in the query string. What is the best way to map a shorter name to this attribute? i.e. ?search[mvlan_contains]
This isn't just a case of wanting to make long attribute names shorter, but I also need to disguise the names of some potentially sensitive attributes for search purposes.
I have looked at alias_attribute
, but couldn't get meta_search to recognise the attribute alias.
I welcome any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以按照rspeicher的建议去做。自定义搜索方法将显示在您的参数列表中。
回复:但是,您的属性中的敏感信息...如果有人知道视图中的属性名称会给您的应用程序带来潜在问题,我会认真考虑在您的模型和控制器层中采取哪些安全步骤。
You could do as rspeicher suggested. The custom search method will be displayed in your parameter list.
Re: sensitive info in your attributes, though... If someone knowing your attribute names in the view poses a potential problem for your application, I'd seriously consider what security steps are being taken in your model and controller layers.