Skip to content

Instantly share code, notes, and snippets.

@lazypower
Created October 27, 2012 18:01
Show Gist options
  • Save lazypower/3965530 to your computer and use it in GitHub Desktop.
Save lazypower/3965530 to your computer and use it in GitHub Desktop.
Problematic Mass Assignment
<div class="field">
<%= f.label :notes %><br />
<%= f.text_area :notes %>
</div>
<div class="field">
<%= f.fields_for :rinkleagues do |builder| %>
<fieldset>
<%= builder.label :rinkleague, "Leagues" %>
<%= builder.collection_select :RinkLeague, RinkLeague.all, :value, :display %>
</fieldset>
<% end %>
</div>
Can't mass-assign protected attributes: rinkleagues, rinksurfaces, developmentalprograms
app/controllers/rinks_controller.rb:43:in `new'
app/controllers/rinks_controller.rb:43:in `create'
{"utf8"=>"✓",
"authenticity_token"=>"x1fV0Snf9A7f2938b/UplmuVFRvPytZSPlCzxO07KPw=",
"rink"=>{"name"=>"",
"address1"=>"",
"address2"=>"",
"addresscity"=>"",
"addressstate"=>"",
"addresszip"=>"",
"phone1"=>"",
"phone2"=>"",
"website"=>"",
"surfacecount"=>"",
"indoor"=>"0",
"openhockey"=>"0",
"sticktime"=>"0",
"proshop"=>"0",
"notes"=>"",
"rinkleagues"=>{"RinkLeague"=>"youth"},
"rinksurfaces"=>{"RinkSurface"=>"ice"},
"developmentalprograms"=>{"DevelopmentalProgram"=>"youth"}},
"commit"=>"Create Rink"}
class Rink < ActiveRecord::Base
attr_accessible :address1, :address2, :addresscity, :addressstate, :addresszip, :indoor, :name, :notes, :openhockey, :phone1, :phone2, :proshop, :sticktime, :surfacecount, :website
attr_accessible :rinkleagues_attributes, :rinksurfaces_attributes, :developmentalprograms_attributes
has_many :RinkLeagues
has_many :RinkSurfaces
has_many :DevelopmentalPrograms
accepts_nested_attributes_for :RinkLeagues
accepts_nested_attributes_for :RinkSurfaces
accepts_nested_attributes_for :DevelopmentalPrograms
end
class RinkLeague < ActiveRecord::Base
attr_accessible :display, :value
belongs_to :Rink
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment