How to Use ActiveRecord Errors #22

hsunami opened this Issue Jun 23, 2012 · 2 comments


None yet

3 participants

hsunami commented Jun 23, 2012

Hi Sutto,

Forgive my n00bness, but I'm a bit confused about this part of the documentation:

Built in ActiveRecord Errors

Out of the box, Rocket Pants will automatically map the following to built in errors and rescue them as appropriate.

ActiveRecord::RecordNotFound into RocketPants::NotFound
ActiveRecord::RecordNotSaved into RocketPants::InvalidResource (with no validation messages).
ActiveRecord::RecordInvalid into RocketPants::InvalidResource (with messages in the "messages" key of the JSON).

If I want to return ActiveRecord errors caused from, how would I do that? How would I use this "ActiveRecord::RecordNotSaved into RocketPants::InvalidResource" for error! ?

Thanks in advance,

Sutto commented Jun 25, 2012

Howdy Jeff,

The answer is pretty simple - if you use save, create etc, just use save!, create! and so forth - these versions throw exceptions when they fail, which RocketPants will automatically rescue from and handle.


Closing for the moment - Let me and I'll reopen if you have more questions.

@filtersquad filtersquad closed this Jul 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment