2013-09-02から1日間の記事一覧

Rails4 リストボックスで複数登録

リストボックスで複数登録するときにちょっと手こずったので、めも。ビューに下記のように記載。 <%= form_for(@sales) do |f| %> <div class="field"> <%= f.label :customer_id %><br> <%= f.select :customer_id, @users.map {|user| [user.name, user.id]}, {:selected=>f.objec</div>…

必要なカラムの値を配列で取得する方法

必要なカラムの値を配列で取得する方法をメモ。UsersテーブルからグループIDが2のユーザーIDを配列で取得したい場合、下記のように記載する。 user_ids = User.select(:id).where(:group_id => 2).map(&:id) 不動産に興味を持ち始めたエンジニアのメモ帳…