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

fix(UniquenessValidator): fill record's scope fields if they exist on form #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DemidenkoAndrey
Copy link

@DemidenkoAndrey DemidenkoAndrey commented Jul 21, 2017

When you try to create new record and we have validates_uniqueness_of with scope we need to assign scope property from form to model to run validation correct

@DemidenkoAndrey DemidenkoAndrey force-pushed the fix/filled-scope-record-in-uniq-validation branch 2 times, most recently from df6fbe1 to d196b1c Compare July 21, 2017 16:41
@DemidenkoAndrey DemidenkoAndrey force-pushed the fix/filled-scope-record-in-uniq-validation branch from d196b1c to 211c82a Compare July 21, 2017 16:41
@seuros
Copy link
Member

seuros commented Jul 21, 2017

Can you write a sample for this usage ?

@DemidenkoAndrey
Copy link
Author

DemidenkoAndrey commented Jul 21, 2017

@seuros
We have to fill region on model to be insure that validation on model will work correct with our region from form

# model
User(name: string, region: string)
class UsersForm < Reform::Form
  include Reform::Form::ActiveRecord
  property :name
  property :region

  validates_uniqueness_of :name, scope: :region

  model :user
end

# users_controller
def create
  user = User.new
  @form = UsersForm.new(user)

  respond_to do |format|
    if @form.validate(user_params)
      @form.save
      format.html { redirect_to @form, notice: 'User was successfully created.' }
    else
      format.html { render :new }
    end
  end
end

def user_params
  params.require(:user).permit(:name, :region)
end

@DemidenkoAndrey
Copy link
Author

@seuros Do you have any update for this issue?

@shadowreplicant
Copy link

+1
@DemidenkoAndrey there is skipped test for it

skip "replace ActiveModel::Validations with our own, working and reusable gem."

@DemidenkoAndrey
Copy link
Author

DemidenkoAndrey commented Dec 14, 2017

@shadowreplicant Thank you for mention that. I've added second commit with removing skip from this test

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

Successfully merging this pull request may close these issues.

3 participants