Sebastian Edler

Joined

60 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Nested attributes permit

Hey!

thank you for your reply.

Unfortunately that seems to be xactly what I have as my code to build the Form
Here is my form.html.erb. I cut out the unnessesary fields, as well as the error handling:

<%= form_with scope: :customer, url: customers_path, local: true  do |form|%>

    <%= form.label :name %>
    <%= form.text_field :name%>

  <p>
    <%= form.fields_for :mails do |mf| %>
      <%= mf.label :mailaddress %>
      <%= mf.text_field :mailaddress %>
    <% end %>
  </p>

  <p>
    <%= form.submit %>
  </p>

<% end %>

Posted in Nested attributes permit

Hey out there,

i am sorry to bother you with my stupid question, but it is important for me, and unfortunately I am not able to find an answer myself.

I have tried to conduct the documentation, but I am unable to find a helpful (to me) anwer.
https://guides.rubyonrails.org/action_controller_overview.html#strong-parameters --> 4.5.2 "nested parameters"

I try to safe a data for two different models, in one go. I use the accepts_nested_attributes_for in the parrent class, and I am able to get the parameters:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"-cut-", "customer"=>
{"name"=>"2222", "city"=>"2222222", "mails"=>{"mailaddress"=>"22222222"}}, "commit"=>"Save Customer"}

But I get en error message:
Unpermitted parameter: :mails

I tried to whitelist the parameters ... but without success:

    private
    def customer_params
      params.require(:customer).permit(
        :name, :city,
        :mails_attributes => [:mailaddress])
    end

What have I done wrong?

Thanks for taking a look!