0

I recently performed a migration turning a string column into a Postgres array. The migration was as follows:

  def change
    change_column :projects, :layout_slug, "varchar[] USING (string_to_array(layout_slug, ','))"
  end

Now, I'm running into an issue with Unpermitted parameters: layout_slug. I've tried all of the accepted answers for the other StackOverflow questions and they're still not working for me. Here are all of the variations I've tried so far:

def project_params
    params.require(:project).permit(:image_slug, { layout_slug: [] }, :category, ..., :selection => [:inputs => Project::ALLOWED_INPUTS.keys])
end

def project_params
    params.require(:project).permit(:image_slug, { :layout_slug => [] }, :category, ..., :selection => [:inputs => Project::ALLOWED_INPUTS.keys])
end

I then tried removing the brackets around :layout_slug => [] and I got an error:

SyntaxError (/.../app/controllers/api/v1/projects_controller.rb:62: syntax error, unexpected ',', expecting =>
... :layout_slug => [], :category, :subcategory, :version, :ema...
...                               ^
/.../app/controllers/api/v1/projects_controller.rb:62: syntax error, unexpected ')', expecting keyword_end
/.../app/controllers/api/v1/projects_controller.rb:165: syntax error, unexpected end-of-input, expecting keyword_end):

# THIS ONE THROWS A SYNTAX ERROR
def project_params
    params.require(:project).permit(:image_slug, :layout_slug => [], :category, :subcategory, :version, :email, :zip_code, :selection => [:inputs => Project::ALLOWED_INPUTS.keys])
end

So then I moved layout_slug to the end, and it went back to throwing the Unpermitted parameters: layout_slug error again.

# This throws the same Unpermitted parameters error as before
def project_params
    params.require(:project).permit(:image_slug, ..., :selection => [:inputs => Project::ALLOWED_INPUTS.keys], :layout_slug => [])
end

I've double- and triple-checked the spelling, and I've verified that the front-end is submitting an Array.

What am I missing?? Was there something wrong with my migration? Or is there something blatantly wrong with my permit method?

1 Answer 1

2

I've tested your sample code and it seems to be fine:

raw_parameters = { :image_slug => "some_slug", :category => "A", :layout_slug => ["a", "b"] }
parameters = ActionController::Parameters.new(raw_parameters)
parameters.permit(:image_slug, :category, :layout_slug => []) 
# {"image_slug"=>"some_slug", "category"=>"A", "layout_slug"=>["a", "b"]}

Check your params :layout_slug format, perhaps that's the case

Sign up to request clarification or add additional context in comments.

Comments

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.