###### tags: `Ruby` 2020/4/6 # 重複的事情放在application.controller  # 製作編輯按鈕   使用新增頁面的表單  重複的事設定為私有方法  依然重複  使用 before_action  將@item 改為item  在new、edit頁面加上item: @item  都能達到一樣的效果  ActiveRecord 是一種設計模式 一種ORM框架 ActiveRecord是一種物件包裹資料列 has_one :store 造出四個方法 store store = build_store create_store belongs_to :owner 生出兩個方法 owner owner= has_one belongs_to需要同時存在嗎? 沒有has_one則Owner無法去查詢store 沒有belongs_to則store無法查詢owner 要不要加看需求 has_many :products products products= # 建立關聯   做選擇列表  新增category_id以防被擋住  先rails g model add_category_to_item 自動造出 model 以及 migration檔 在migration下指令在下rails db:migrate # 檢查登入  
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up