私はpostgres dbでrails 4を使用しており、配列を試しています。しかし、クエリを機能させることができません。
私はこれまでのところこれを持っています:
@contacts = current_firm.contacts.order(:name)
params[:show] をクエリに追加したいので、contactType 列に「place」などを含むレコードのみが表示されます。URL が contacts?show=place の場合。
私はこれを何時間も理解しようとしたので、あなたが助けてくれることを本当に願っています.
スキーマ:
create_table "contacts", force: true do |t|
t.integer "firm_id"
t.string "contactType", array: true
t.string "name"
t.string "adress"
t.integer "zipcode"
t.string "town"
t.string "country", default: "DK"
t.integer "cvr"
t.string "email"
t.string "contact"
t.string "phone"
t.string "cellPhone"
t.string "website"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "deleteFlag", default: false
end
Contact.all のコンソール ダンプ
#<ActiveRecord::Relation
[#<
Contact id: 7,
firm_id: 5,
contactType: ["customer", "place"],
name: "PA Syd",
adress: "",
zipcode: nil,
town: "",
country: "DK",
cvr: nil, email: "",
contact: "Lars Opstrup",
phone: "",
cellPhone: nil,
website: "",
created_at: "2013-06-28 13:29:18",
updated_at: "2013-06-28 13:29:18",
deleteFlag: false
>,
#<
Contact id: 1,
firm_id: 5,
contactType: ["place"],
name: "Mads Ellesgaard",
adress: "",
zipcode: 6400,
town: "Soenderborg",
country: "DK",
cvr: nil,
email: "mads@example.dk",
contact: "",
phone: "",
cellPhone: nil,
website: "",
created_at: "2013-06-28 11:58:58",
updated_at: "2013-06-29 09:35:39",
deleteFlag: false
>
]>