您的位置:首页 > 理论基础 > 计算机网络

HttpClient做接口测试时自定义参数长度

2016-01-14 13:49 471 查看
Searchlogic makes searching models easier than ever with its assortment of named scopes. In this episode I show you how to create simple and advanced searches.

sudo gem install searchlogic
# config/environment.rb
config.gem "searchlogic"

# script/console
ActiveRecord::Base.logger = Logger.new(STDOUT)
Product.name_like("Video")
Product.name_not_like("Video").price_gt(5).price_lt(200)
Product.name_like_any(["couch", "table"])
Product.name_like_all(["video", "console"])
Product.category_name_like("elect")
Product.search(:category_name_like => "elect", :price_lt => "100")
s = _
s.all
s.name_like("video")
Product.ascend_by_name

# products_controller.rb
@products = Product.name_like_all(params[:search].to_s.split).ascend_by_name
# or
@search = Product.search(params[:search])
@products = @search.all
<!-- index.html.erb -->
<% form_for @search do |f| %>
<p>
<%= f.label :name_like, "Name" %><br />
<%= f.text_field :name_like %>
</p>
<p>
<%= f.label :category_id_equals, "Category" %><br />
<%= f.collection_select :category_id_equals, Category.all, :id, :name, :include_blank => true %>
</p>
<p>
<%= f.label :price_gte, "Price Range" %><br />
<%= f.text_field :price_gte, :size => 8 %> - <%= f.text_field :price_lte, :size => 8 %>
</p>
<p>
<%= f.submit "Submit" %>
</p>
<% end %>

<p>
Sort by:
<%= order @search, :by => :name %> |
<%= order @search, :by => :price %>
</p>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: