- 追加された行はこの色です。
- 削除された行はこの色です。
&tag(Rails/デモアプリ);
*目次 [#v1c02e78]
#contents
*関連ページ [#nfe33de8]
-[[Rails4]]
*参考情報 [#ad91a49a]
-[[開発現場でちゃんと使えるRails 4入門(2):scaffoldの中身を理解するためにMVCコンポーネントと7つのアクションを個別で自作する (1/3) - @IT:http://www.atmarkit.co.jp/ait/articles/1403/28/news035.html]]
*基本アプリの作成[#l3e2b8c1]
**概要 [#ib6651bc]
-本一覧を表示する簡単なアプリを作成する。
**SQLite3の場合 [#f64f1ed1]
***生成 [#s3c09e81]
-Rails4.1ではデフォルトでSQLiteを使うようになっている。
bundle exec rails new ~/work/demo --skip-bundle
***scaffold [#u646935d]
-scaffold実行
bundle exec rails generate scaffold book title:string author:string summary:text
-migrate実行
bundle exec rake db:migrate RAILS_ENV=development
-WEBRickを起動し http://localhost:3000/booksで一覧にアクセスできる。
bundle exec rails s -e development
**MySQLの場合 [#m4b2021a]
***生成 [#dd608abe]
-引数で指定する
bundle exec rails new ~/work/demo --skip-bundle --database=mysql
***データベースユーザーの生成 [#td179fe7]
-create_user.sqlとして保存し、mysql -uroot -pXXX mysql < create_user.sqlで実行。
#pre{{
-- mysql -uroot -pXXX mysql < create_user.sqlで実行
grant all privileges on *.* to testuser identified by ’testpasswd';
grant all privileges on *.* to testuser@localhost identified by ’testpasswd';
}}
***データベースの作成 [#cc54bf26]
-config/database.ymlを編集。username、passwordを設定。
***scaffold [#hae06a8d]