Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad syntax in model validation throws error in controller #30156

Closed
bplmp opened this issue Aug 9, 2017 · 1 comment
Closed

Bad syntax in model validation throws error in controller #30156

bplmp opened this issue Aug 9, 2017 · 1 comment

Comments

@bplmp
Copy link

bplmp commented Aug 9, 2017

Steps to reproduce

  1. Create a Product model with this validation which has bad syntax: validates_uniqueness_of :code, :scope => [:archived => false]
  2. Try to update any attribute for Product.

Expected behavior

An error that points to the bad syntax in the model validation for Product.

Actual behavior

Throws the following error undefined method 'to_sym' for {:archived=>false}:Hash Did you mean? to_s to_yaml to_set.

The error points to the if @product.update(product_params) line in the ProductsController. Full update method is:

  def update
    @product = Product.find(params[:id])
  
    if @product.update(product_params)
      redirect_to @product
    else
      render 'edit'
    end
  end

System configuration

Rails version:
rails (5.0.0.1)

Ruby version:
ruby 2.3.0p0

Has been discussed in this Stack Overflow question.

@rafaelfranca
Copy link
Member

I think we should check if scope is a symbol when calling validates_uniqueness_of . Could you open a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants