0

I have inputs which get loaded over ajax and get's inserted in a other form with javascript with this fields:

<input name="project[config][service][3][web][auth]" type="checkbox">

and two other inputs with:

<input type="text" name="project[config][service][3][web][user]">
<input type="text" name="project[config][service][3][web][pass]">

how can I permit this to the controller to accept the values?

I tried it with these:

params.require(:project).permit(
        :title,
        :description,
        config: [
            service: {
                [] => [
                    :domains,
                    web: [
                        :auth,
                        :user,
                        :pass
                    ]
                ]
            }
        ],
        documents: []
      )

but it didn't worked. In the console i have this as project_params[:config]

{"service"=><ActionController::Parameters {"3"=><ActionController::Parameters {} permitted: true>} permitted: true>}

the params[:project][:config] looks like this:

{
  "service" => { 
    "3" => {
      "web" => {
        "auth"=>"on",
        "user"=>"asdasdasdasda",
        "pass"=>"asdasdasd"
      }
    }
  }
}

1 Answer 1

1

Try it this way, it should work:

params.require(:project).permit(
       :title, 
       :description, 
       config: {
         service: [
           :domains,
           web: [:auth, :user, :pass]
         ]
       },
       documents: []
     )
Sign up to request clarification or add additional context in comments.

2 Comments

yes, thanks! But can you explain why or whats wrong with my? :)
@Evolutio problem is on the part of service: { [] => [ definition. The hash you've added when the key is an empty array. You don't have to do that. Rails recognise an array by numbers in the keys and do the array processing for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.