Created
December 13, 2014 10:03
-
-
Save anonymous/601ba9300fa462c6d4ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bar < ActiveRecord::Base | |
belongs_to :foo | |
has_many :bazs | |
accepts_nested_attributes_for :bazs | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Baz < ActiveRecord::Base | |
belongs_to :bar | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started POST "/foos" for 127.0.0.1 at 2014-12-13 11:00:53 +0100 | |
Processing by FoosController#create as HTML | |
Parameters: {"utf8"=>"✓", "authenticity_token"=>"eLWiAFnILPySsw/b5h+BRtsk0UTbNJlsiTnllXvJuLuZGtxprb4lYTBmnvXsWqbmYnl3Rls0nW1tLz4+ydlu/w==", "foo"=>{"name"=>"foo", "bars_attributes"=>{"0"=>{"name"=>"bar1", "bazs_attributes"=>{"0"=>{"name"=>"baz1"}}}, "1"=>{"name"=>"bar2", "bazs_attributes"=>{"0"=>{"name"=>"baz2"}}}}}, "commit"=>"Create Foo"} | |
Completed 500 Internal Server Error in 1ms | |
ActionView::MissingTemplate (Missing template foos/create, application/create with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby]}. Searched in: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < ActiveRecord::Base | |
has_many :bars | |
accepts_nested_attributes_for :bars | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FoosController < ApplicationController | |
def new | |
@foo = Foo.new | |
@foo.bars.build | |
@foo.bars.build | |
@foo.bars.first.bazs.build | |
@foo.bars.last.bazs.build | |
end | |
private | |
def foo_params | |
params.require(:foo).permit(:name, bars_attributes: [:name, bazs_attributes: [:name]]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @foo do |f| %> | |
<p><%= f.text_field :name %></p> | |
<%= f.fields_for :bars do |bar| %> | |
<%= bar.text_field :name %> | |
<%= bar.fields_for :bazs do |baz| %> | |
<%= baz.text_field :name %> | |
<% end %> | |
<% end %> | |
<p><%= f.submit %></p> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
resource :foos | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment