個人開発がデプロイまでに近づいてきたので、開発過程を順を追って書いていこうと思いました。
タイトル:spoon
使用言語:HTML(haml)、CSS(SCSS)、Ruby、Ruby on Rails、JavaScript、jQuery
ツール:Git、GitHub、MysQL
環境:Mac、ruby 2.5.1
なぜ作ろうと思ったのか?
趣味で釣りをやっているのですが、自分が興味のあるものを作ろうと思い立ったのがきっかけです。釣り具の販売サイトはたくさんあるので、売買を行うのはルアーの”スプーン”を中心に行うアプリにしようと決めました。
コンセプトは”自分で作って販売出来る”、売買する商品は”500円一律”で作り方のyoutyubuの埋め込みなどでアプリとしての使いやすさを意識しようと考えました。
誰のために作ったのか?
自分でルアーを作る方はネットや個人店で見かけたりしていたので、 釣りの好きな人、作るのが好きな人にとって、ちょっと面白いと思ってもらえることを目指して作成していました。
アプリの大まかな構想が決まってから、他のwebアプリを参考にアプリを立ち上げてにDB設計を考えることから始めました。
〜今回の記事の内容 〜
☆コンセプト、構想を練る
⬇︎
☆アプリを立ち上げ
⬇︎
Gitを利用して管理
⬇︎
DB設計(データベース設計)
アプリの立ち上げ
RubyとRailsでアプリを作っていきます
今回はMysQLにてデータベースを管理するためアプリ名の後にオプションを追記します
rails new アプリ名 --オプション
これで、アプリが立ち上がりました
アプリを立ち上げたところで、まずはViewを作り見やすくした方が良いかなと思い
$ rails db:createを実行します
下記のエラーが発生
Database 'db/development.sqlite3' already exists
Created database 'db/test.sqlite3'
silver:testes horayuki$
調べてみるとRailsのデフォルトのデータベースがsqlite3のため設定しなければ、自動で作られてしまうそうです、解決するためには下記の手順を踏んでいきます
まず、datebese.yamlについて各詳細を書いておきます
adapter: 使用するデータベース種類
reconnect: 再接続するかどうか
database: データベース名
pool: コネクションプーリングで使用するコネクションの上限
username: ユーザー名
password: パスワード
config/datebese.yaml内の記述を下記の内容に書き換えていきます
datebese.yml
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
こちらの内容に書き換えます
datebese.yml
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password:
development:
<<: *default
database: spoon_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: spoon_test
production:
<<: *default
database: spon_production
username: spoon
password: <%= ENV['Sample_PASSWORD'] %>
gemfileの内容も変更します
gemfileのこちらの行を
下記のように書き換えます
gemをアプリに取り入れるためにbundle installを行います
再び$ rails db:createを実行します
これで、MysQLでデータベースを作ることが出来ました
あとは、$ rails g controller コントローラー名 で作り、ルーティングを設定すれば、画面表示できるようになります
参考記事:https://qiita.com/reeenapi/items/9fc38c4f2f8186c78288#%E5%88%9D%E3%82%81%E3%81%8B%E3%82%89%E5%A4%89%E6%9B%B4%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95
今回はここまで!続きはまた次回書いていきます!