サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
おみそ汁
kawahiro.hatenablog.jp
案件で複数データベースの使用が必要になったので、いろいろやり方を調べて自分なりにまとまってきたのでメモ。 接続先の情報をconfig/database2.ymlファイルを新規作成して記述 # 2つめのデータベースの設定 development: adapter: postgresql encoding: unicode database: hoge_development pool: 5 username: postgres password: test: adapter: postgresql encoding: unicode database: hoge_test pool: 5 username: postgres password: production: adapter: postgresql encoding: unicode database: hoge_productio
都道府県を選んだら市区町村が絞り込まれるとかよくあるやつ。 今回は会社登録時に都道府県と市区町村をプルダウンで選べるみたいな設定で考える。 都道府県、市区町村、会社のモデルとそれぞれのリレーションはこんな感じ。 # ms_pref.rb class MsPref < ActiveRecord::Base has_many :ms_cities end # ms_city.rb class MsCity < ActiveRecord::Base belongs_to :ms_pref end # company.rb class Company < ActiveRecord::Base belongs_to :ms_pref belongs_to :ms_city end まずはviewで市区町村のプルダウンをpartial化する。 # _form.html.slim = form_for
このページを最初にブックマークしてみませんか?
『kawahiro.hatenablog.jp』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く