Skip to content

Instantly share code, notes, and snippets.

@brylor
Last active August 29, 2015 14:16
Show Gist options
  • Save brylor/a62fe625462630e1a778 to your computer and use it in GitHub Desktop.
Save brylor/a62fe625462630e1a778 to your computer and use it in GitHub Desktop.
class Task < ActiveRecord::Base
belongs_to :project
end
class Project < ActiveRecord::Base
has_many :tasks
accepts_nested_attributes_for :tasks
end
# GET /projects/new
def new
@project = Project.new
@project.tasks.build
end
...
def project_params
params.require(:project).permit(:name, tasks_attributes:[:id, :name, :project_id])
end
<%= form_for(@project) do |f| %>
...
<h4>Tasks<h4>
<%= f.fields_for :tasks do |s| %>
<%= s.text_field :name %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment