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

More specific validation error? #223

Open
nathanl opened this issue Dec 4, 2012 · 4 comments
Open

More specific validation error? #223

nathanl opened this issue Dec 4, 2012 · 4 comments

Comments

@nathanl
Copy link
Contributor

nathanl commented Dec 4, 2012

I've just spent a while chasing down a mysterious "is invalid" validation error. Turns out that the problem was that this attribute is managed by state_machine and the value I set was not one of its states.

A message like "is not a valid state_machine state" would have been much clearer.

Thoughts?

@nathanl
Copy link
Contributor Author

nathanl commented Dec 4, 2012

Ah, poop-on-a-stick! You can't do that because users would see it and be confused.

This is not the first time I've wished for separate developer-facing and user-facing validation errors.

@the8472
Copy link

the8472 commented Dec 4, 2012

Well, you can easily roll your own simply by mixing a module into AR:Base that lazy-initializes your own error object and calls a before_validate that marks the "real" error object as invalid if something is present in the internal one.

Then you can write a validation handler for the state machine to see if the state is included in the current machine. Should only be a few LOC.

@nathanl
Copy link
Contributor Author

nathanl commented Dec 4, 2012

Yeah, I was thinking about this more as a usability improvement for all developers. Now that I'm aware of it, I can figure it out easily; just wanted to spare others the pain.

@the8472
Copy link

the8472 commented May 7, 2013

Ah, for the particular state attribute validation I've written an :after_initialize hook that verifies that the state is valid and sets the attribute to a "you fucked up" state (known to the state machine) if it's not.

That in turn allows the user to transition to any other target state.

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

No branches or pull requests

2 participants