0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rails データ保存あれこれ

Posted at

基本

new → view → controller

  • 通常
def product_params
 params.require(:product).permit(:name, :desc)
end

fields_for



1対多で子要素もまとめて保存する


# prodcut.rb
 def product_params
   params.require(:product).permit(:name, :desc, production_conditions_attributes:[:name])
 end

class Product < ApplicationRecord
  has_many :production_conditions
  has_many :somethings, as: :somethingable
  accepts_nested_attributes_for :production_conditions

ポリモーフィック

  • commentableでnewする必要ありみたい

※参考記事
https://ruby-rails.hatenadiary.com/entry/20141207/1417926599

参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?