Error when submitting form: Nested attributes unpermitted parameters





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I've tried the solutions on this other stack overflow question but they aren't working.



I'm getting this error when submitting my form: Unpermitted parameter: organization_required_fields



Any help would be appreciated.



I have the following models:



class Organization < ActiveRecord::Base
belongs_to :user
has_many :organization_required_fields
has_many :fields, through: :organization_required_fields

accepts_nested_attributes_for :organization_required_fields, allow_destroy: true
end

class OrganizationRequiredField < ActiveRecord::Base
belongs_to :organization
belongs_to :field
end

class Field < ActiveRecord::Base
has_many :organization_required_fields
has_many :organizations, through: :organization_required_fields
end


My controller:



def update
...
@organization.update(organization_params)
...
end

private
def set_organization
@organization = Organization.find_by_id(params[:id])
...
end

def organization_params
params.require(:organization).permit(:name, :user_id, organization_required_fields_attributes: [:id, :organization_id, :field_id, :_destroy])
end


My form view



...
= f.select :organization_required_fields, options_for_select(@fields.collect {|rf| [ rf.name.titleize, rf.id ] }, @organization.fields.collect{ |orf| orf.id }),{ :prompt => "Please select"},{ :multiple => true, :size => 15 }
...









share|improve this question























  • I don't really get why you would add a separate OrganizationRequiredField model and association unless the definition of the fields attached to an organization are not a developer concern (not defined by the db schema) and must be user editable.

    – max
    Nov 16 '18 at 23:48













  • That is why i added the model. They are user edited.

    – Chris
    Nov 18 '18 at 2:59


















0















I've tried the solutions on this other stack overflow question but they aren't working.



I'm getting this error when submitting my form: Unpermitted parameter: organization_required_fields



Any help would be appreciated.



I have the following models:



class Organization < ActiveRecord::Base
belongs_to :user
has_many :organization_required_fields
has_many :fields, through: :organization_required_fields

accepts_nested_attributes_for :organization_required_fields, allow_destroy: true
end

class OrganizationRequiredField < ActiveRecord::Base
belongs_to :organization
belongs_to :field
end

class Field < ActiveRecord::Base
has_many :organization_required_fields
has_many :organizations, through: :organization_required_fields
end


My controller:



def update
...
@organization.update(organization_params)
...
end

private
def set_organization
@organization = Organization.find_by_id(params[:id])
...
end

def organization_params
params.require(:organization).permit(:name, :user_id, organization_required_fields_attributes: [:id, :organization_id, :field_id, :_destroy])
end


My form view



...
= f.select :organization_required_fields, options_for_select(@fields.collect {|rf| [ rf.name.titleize, rf.id ] }, @organization.fields.collect{ |orf| orf.id }),{ :prompt => "Please select"},{ :multiple => true, :size => 15 }
...









share|improve this question























  • I don't really get why you would add a separate OrganizationRequiredField model and association unless the definition of the fields attached to an organization are not a developer concern (not defined by the db schema) and must be user editable.

    – max
    Nov 16 '18 at 23:48













  • That is why i added the model. They are user edited.

    – Chris
    Nov 18 '18 at 2:59














0












0








0








I've tried the solutions on this other stack overflow question but they aren't working.



I'm getting this error when submitting my form: Unpermitted parameter: organization_required_fields



Any help would be appreciated.



I have the following models:



class Organization < ActiveRecord::Base
belongs_to :user
has_many :organization_required_fields
has_many :fields, through: :organization_required_fields

accepts_nested_attributes_for :organization_required_fields, allow_destroy: true
end

class OrganizationRequiredField < ActiveRecord::Base
belongs_to :organization
belongs_to :field
end

class Field < ActiveRecord::Base
has_many :organization_required_fields
has_many :organizations, through: :organization_required_fields
end


My controller:



def update
...
@organization.update(organization_params)
...
end

private
def set_organization
@organization = Organization.find_by_id(params[:id])
...
end

def organization_params
params.require(:organization).permit(:name, :user_id, organization_required_fields_attributes: [:id, :organization_id, :field_id, :_destroy])
end


My form view



...
= f.select :organization_required_fields, options_for_select(@fields.collect {|rf| [ rf.name.titleize, rf.id ] }, @organization.fields.collect{ |orf| orf.id }),{ :prompt => "Please select"},{ :multiple => true, :size => 15 }
...









share|improve this question














I've tried the solutions on this other stack overflow question but they aren't working.



I'm getting this error when submitting my form: Unpermitted parameter: organization_required_fields



Any help would be appreciated.



I have the following models:



class Organization < ActiveRecord::Base
belongs_to :user
has_many :organization_required_fields
has_many :fields, through: :organization_required_fields

accepts_nested_attributes_for :organization_required_fields, allow_destroy: true
end

class OrganizationRequiredField < ActiveRecord::Base
belongs_to :organization
belongs_to :field
end

class Field < ActiveRecord::Base
has_many :organization_required_fields
has_many :organizations, through: :organization_required_fields
end


My controller:



def update
...
@organization.update(organization_params)
...
end

private
def set_organization
@organization = Organization.find_by_id(params[:id])
...
end

def organization_params
params.require(:organization).permit(:name, :user_id, organization_required_fields_attributes: [:id, :organization_id, :field_id, :_destroy])
end


My form view



...
= f.select :organization_required_fields, options_for_select(@fields.collect {|rf| [ rf.name.titleize, rf.id ] }, @organization.fields.collect{ |orf| orf.id }),{ :prompt => "Please select"},{ :multiple => true, :size => 15 }
...






ruby-on-rails activerecord






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 19:44









ChrisChris

2,01721226




2,01721226













  • I don't really get why you would add a separate OrganizationRequiredField model and association unless the definition of the fields attached to an organization are not a developer concern (not defined by the db schema) and must be user editable.

    – max
    Nov 16 '18 at 23:48













  • That is why i added the model. They are user edited.

    – Chris
    Nov 18 '18 at 2:59



















  • I don't really get why you would add a separate OrganizationRequiredField model and association unless the definition of the fields attached to an organization are not a developer concern (not defined by the db schema) and must be user editable.

    – max
    Nov 16 '18 at 23:48













  • That is why i added the model. They are user edited.

    – Chris
    Nov 18 '18 at 2:59

















I don't really get why you would add a separate OrganizationRequiredField model and association unless the definition of the fields attached to an organization are not a developer concern (not defined by the db schema) and must be user editable.

– max
Nov 16 '18 at 23:48







I don't really get why you would add a separate OrganizationRequiredField model and association unless the definition of the fields attached to an organization are not a developer concern (not defined by the db schema) and must be user editable.

– max
Nov 16 '18 at 23:48















That is why i added the model. They are user edited.

– Chris
Nov 18 '18 at 2:59





That is why i added the model. They are user edited.

– Chris
Nov 18 '18 at 2:59












2 Answers
2






active

oldest

votes


















0














I actually changed a lot by following this rails cast



I also had to change the organization_params to



params.require(:organization).permit(:name, :user_id, { field_ids: })






share|improve this answer































    0














    You need to use fields_for in your form.






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344385%2ferror-when-submitting-form-nested-attributes-unpermitted-parameters%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      I actually changed a lot by following this rails cast



      I also had to change the organization_params to



      params.require(:organization).permit(:name, :user_id, { field_ids: })






      share|improve this answer




























        0














        I actually changed a lot by following this rails cast



        I also had to change the organization_params to



        params.require(:organization).permit(:name, :user_id, { field_ids: })






        share|improve this answer


























          0












          0








          0







          I actually changed a lot by following this rails cast



          I also had to change the organization_params to



          params.require(:organization).permit(:name, :user_id, { field_ids: })






          share|improve this answer













          I actually changed a lot by following this rails cast



          I also had to change the organization_params to



          params.require(:organization).permit(:name, :user_id, { field_ids: })







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 21:26









          ChrisChris

          2,01721226




          2,01721226

























              0














              You need to use fields_for in your form.






              share|improve this answer




























                0














                You need to use fields_for in your form.






                share|improve this answer


























                  0












                  0








                  0







                  You need to use fields_for in your form.






                  share|improve this answer













                  You need to use fields_for in your form.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 17 '18 at 5:03









                  DorianDorian

                  13.4k37889




                  13.4k37889






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344385%2ferror-when-submitting-form-nested-attributes-unpermitted-parameters%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Xamarin.iOS Cant Deploy on Iphone

                      Glorious Revolution

                      Dulmage-Mendelsohn matrix decomposition in Python