Skip to content

Instantly share code, notes, and snippets.

@brylor
Forked from anonymous/Projection.rb
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brylor/71c19e13c59cb92fd6bd to your computer and use it in GitHub Desktop.
Save brylor/71c19e13c59cb92fd6bd to your computer and use it in GitHub Desktop.
<%= f.fields_for :incomes do |income| %>
<%= income.label :name %>
<%= income.text_field :name %>
<%= income.label :amount %>
<%= income.text_field :amount %>
<% end %>
ActionController::UnpermittedParameters in ProjectionsController#update
found unpermitted parameters: incomes
Parameters:
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"XwA325J64foUZ6I33rNe2Ec4pRqAfHxxW711CBz/jws=",
"projection"=>{"name"=>"help",
"incomes"=>{"name"=>"adfaf",
"amount"=>"323"}},
"commit"=>"Update Projection",
"id"=>"6"}
class Income < ActiveRecord::Base
has_many :income_projections
has_many :projections, :through => :income_projections
accepts_nested_attributes_for :income_projections
end
income_projection.rb
class IncomeProjection < ActiveRecord::Base
belongs_to :income
belongs_to :projection
end
class Projection < ActiveRecord::Base
has_many :income_projections
has_many :incomes, :through => :income_projections
accepts_nested_attributes_for :income_projections
def update(post_params)
...
def edit
@projection = Projection.find(params[:id])
@incomes = @projection.incomes
end
...
def update
respond_to do |format|
if @projection.update(projection_params)
format.html { redirect_to @projection, notice: 'Projection was successfully updated.' }
format.json { render :show, status: :ok, location: @projection }
else
format.html { render :edit }
format.json { render json: @projection.errors, status: :unprocessable_entity }
end
end
end
def projection_params
params.require(:projection).permit(:name,
:incomes,
income_projections_attributes: [:id,:projection_id, :amount, :name, '_destroy']
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment