-
-
Save brylor/71c19e13c59cb92fd6bd 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
<%= f.fields_for :incomes do |income| %> | |
<%= income.label :name %> | |
<%= income.text_field :name %> | |
<%= income.label :amount %> | |
<%= income.text_field :amount %> | |
<% 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
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"} |
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 Income < ActiveRecord::Base | |
has_many :income_projections | |
has_many :projections, :through => :income_projections | |
accepts_nested_attributes_for :income_projections | |
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
income_projection.rb | |
class IncomeProjection < ActiveRecord::Base | |
belongs_to :income | |
belongs_to :projection | |
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 Projection < ActiveRecord::Base | |
has_many :income_projections | |
has_many :incomes, :through => :income_projections | |
accepts_nested_attributes_for :income_projections | |
def update(post_params) | |
... |
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
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