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

Adding Errors #257

Closed
guizmaii opened this issue Feb 10, 2015 · 2 comments
Closed

Adding Errors #257

guizmaii opened this issue Feb 10, 2015 · 2 comments
Assignees
Labels

Comments

@guizmaii
Copy link

I don't understand why when I write this in my interaction :

errors.add(:no_way)

and I have the following error :

NoMethodError - undefined method `no_way'

I need to write this :

errors.add(:no_way, 'no_way')

in order to correctly add an error.
The add_sym method has the same behavior.

@tfausak tfausak self-assigned this Feb 10, 2015
@tfausak
Copy link
Collaborator

tfausak commented Feb 10, 2015

This behavior actually comes from ActiveModel. In general, you can't add errors to an attribute that doesn't exist on a model. So this code will raise an error:

class Example < ActiveInteraction::Base
  def execute
    errors.add :no_way
  end
end
Example.run!

While this code won't:

class Example < ActiveInteraction::Base
  boolean :no_way
  def execute
    errors.add :no_way
  end
end
Example.run!

@guizmaii
Copy link
Author

Ok. Thank you for the answer.

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

No branches or pull requests

2 participants