$ git branch
* main
$ git pull origin main
$ git switch -c 20230830
【 VSCode側 】
$ git status
$ git add .
$ git commit -m "Scopeの定義"
$ git branch
* 20230830
main
$ git push origin 20230830 または git push origin @
【 GitHub側 】
【 HackMD 】
ノートの読んだところにPRのURLを追記しておく。
$ bin/rails db:migrate
2-2-1 書籍のデータを作る。
(1..5).each do |i|
Book.create(
name: "Book #{i}",
published_on: Time.parse("20191224").ago(i.months),
price: (i * 1000),
)
end
class Book < ApplicationRecord
scope :costly, -> { where("price > ?", 3000) }
end
リスト2.4 app/models/book.rbにwritten_aboutスコープを追加する
class Book < ApplicationRecord
scope :costly, -> { where("price > ?", 3000) }
scope :written_about, ->(theme) { where("name like ?","%#{theme}%") }
scope :find_price, ->(price) { find_by(price: price) }
end
リスト2.5 db/migrate/20200514152514_add_publisher_id_to_books.rb
class AddPublisherIdToBooks < ActiveRecord::Migration[6.0]
def change
add_reference :books, :publisher, foreign_key: true
end
end
リスト2.6
class AddPublisherIdToBooks < ActiveRecord::Migration[6.0]
def change
add_reference :books, :publisher, foreign_key: true
change_column :books, :publisher_id, :integer, :null: false
end
end
リスト2.7
class Book < ApplicationRecord
has_many :books
end
リスト2.8
class Book < ApplicationRecord
scope :costly, -> { where("price > ?", 3000) }
scope :written_about, ->(theme) { where("name like ?","%#{theme}%") }
belongs_to :publisher
end
$ rails c
publisher = Publisher.create(
name: "Gihyo inc.",
address: "Ichigaya",
)
publisher.books << Book.create(
name: "Book 1",
published_on: Time.current,
price: 1000,
)
publisher.books << Book.create(
name: "Book 2",
published_on: Time.current,
price: 2000,
)
リスト2.10のあとのrails cのコード
(データを作る部分だけ抜粋)
$ bin/rails c
matz = Author.create(name: "Matsumoto Yukihiro", penname: "Matz")
dhh = Author.create(name: "David Heinemeier Hannson", penname: "DHH")
matz.books << Book.find(1)
matz.books << Book.find(2)
book = Book.find(1)
book.authors << dhh
2-2-3
$ bin/rails c
Book.create(
name: "RailsBook",
published_on: Time.parse("20191224").ago(2.months),
price: 2980,
publisher: Publisher.find(1),
)
【 GitHub側 】
Github上のNewアイコン
をクリックして空のリポジトリ作成。
リポジトリ名、Descriptionを記入。
(例:Perfect_Ruby_on_Rails_Ch2)、(例:パーフェクトRuby on Rails 輪読会 2023 2章用)
【 VSCode側 】
$ git clone https://github.com/KMZ0209/Perfect_Ruby_on_Rails_Ch2.git
$ git switch -c main
.gitignore
ファイルを作成する
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
.bundle
# Ignore the default SQLite database.
/*/db/*.sqlite3
/*/db/*.sqlite3-journal
/*/db/*.sqlite3-*
# Ignore all logfiles and tempfiles.
/*/log/*
/*/tmp/*
!/*/log/.keep
!/*/tmp/.keep
# Ignore pidfiles, but keep the directory.
/*/tmp/pids/*
!/*/tmp/pids/
!/*/tmp/pids/.keep
# Ignore uploaded files in development.
/*/storage/*
!/*/storage/.keep
/*/public/assets
.byebug_history
# Ignore master key for decrypting credentials and more.
/*/config/master.key
/*/public/packs
/*/public/packs-test
node_modules
yarn-error.log
yarn-debug.log*
.yarn-integrity
編集していく(ローカルでrails new してbook_adminを作成するなど)。
(rails new
する手順はこちら→環境構築 2023年版 - HackMD)
$ rails new book_admin --skip-action-mailer --skip-action-mailbox --skip-action-text --skip-active-text --skip-active-storage --skip-action-cable
$ git add .
$ git commit -m 'rails new'
$ git push origin https://github.com/KMZ0209/Perfect_Ruby_on_Rails_Ch2
【 GitHub側 】
ヘッダーメニューからSettingsを選択。
左側のメニューでCollaboratorsを選択。
Add peopleボタンから更新してくれる方を招待していく
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing