所以,假设我有一个Customer带有数组列的模型phones.通过手机找到所有客户非常容易
Customer.where('? = ANY(phones)', '+79851234567')
Run Code Online (Sandbox Code Playgroud)
但是LIKE,当我想找到类似于给定电话的客户时,我无法弄清楚如何使用通配符,例如:
Customer.where('ANY(phones) LIKE ?', '+7985%')
Run Code Online (Sandbox Code Playgroud)
我正在使用PostgreSQL 9.5和Rais 4.2
有任何想法吗?
我有一个包含许多图像的目录项,并尝试使用嵌套表单和载波通过一个请求上传所有图像。我也使用响应者、haml 和简单的形式。所以,它是这样的:
项目.rb
class Item < ActiveRecord::Base
has_many :images, dependent: :destroy
accepts_nested_attributes_for :images
end
Run Code Online (Sandbox Code Playgroud)
图像.rb
class Image < ActiveRecord::Base
belongs_to :item
mount_uploader :image, ImageUploader
end
Run Code Online (Sandbox Code Playgroud)
_form.html.haml
= simple_form_for(@item, :html => {:multipart => true }) do |f|
= f.error_notification
.form-inputs
= f.input :name
= f.input :description
= f.input :price
= simple_fields_for :images do |image|
= image.file_field :image, multiple: true
.form-actions
= f.button :submit
Run Code Online (Sandbox Code Playgroud)
items_controller.rb
...
def new
@item = Item.new
respond_with(@item)
end
def create
@item = Item.new(item_params)
@item.save
respond_with(@item)
end
... …Run Code Online (Sandbox Code Playgroud)