Skip to content

Instantly share code, notes, and snippets.

@adamyonk
Last active December 17, 2015 10:19
Show Gist options
  • Save adamyonk/5593868 to your computer and use it in GitHub Desktop.
Save adamyonk/5593868 to your computer and use it in GitHub Desktop.
Rails 4, Strong Parameters, and Nested Forms
= form_for @album do |f|
= f.text_field :title
= f.fields_for :songs do |s|
= s.text_field :name
...
class Album < ActiveRecord::Base
has_many :songs
accepts_nested_attributes_for :songs, allow_destroy: true
...
end
class AlbumsController < ApplicationController
...
private
def album_params
params.require(:album).permit(:title, songs_attributes: [:id, :_destroy, :name])
end
end
class Song < ActiveRecord::Base
belongs_to :album
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment