dm-devise icon indicating copy to clipboard operation
dm-devise copied to clipboard

Support global raise_on_save_failure = true

Open singhman13 opened this issue 14 years ago • 4 comments

Support setting globally on start up:

DataMapper::Model.raise_on_save_failure = true

singhman13 avatar Sep 10 '11 01:09 singhman13

I'm not clear on why anything would need to be added to dm-devise. Couldn't you just add that line to application.rb or an initializer? I'm probably missing something, though.

jm81 avatar Sep 10 '11 01:09 jm81

Basically dm-devise assumes the value for raise_on_save_failure is always false and as such when it is true the following occurs if validation fails:

DataMapper::SaveFailureError in MyDevise::RegistrationsController#create

User#save returned false, User was not saved

One solution is to explicitly set @user.raise_on_save_failure = false at the instance level in the controller actions so that you can still use the return code from save as the test instead of catching the exception.

This would make the dm-devise implementation independent of the global setting.

singhman13 avatar Sep 10 '11 02:09 singhman13

Ah, I think I see now.

dm-devise doesn't actually provide any controllers, but uses the controllers from devise (in https://github.com/plataformatec/devise/tree/master/app/controllers/devise; more precisely, all dm-devise does is make sure DataMapper models respond to all the methods devise expects in the way it expects). I'm guessing that only RegistrationsController would need to be changed, but not immediately sure what's the best way to go about adding that to dm-devise. If you want to work on it and provide a patch, that would be great; otherwise, I'll try to work on this later next week.

jm81 avatar Sep 10 '11 14:09 jm81

I haven't made any progress on this. I don't have any experience with using controllers in plugins, so I'm fighting a learning curve on that. dm-devise could have its own set of controllers, but that strikes me as a maintenance headache. Hopefully I'll either have some inspiration or time to dig into this further (it wouldn't surprise if this is actually really easy if I just knew more), or someone else can work on this.

jm81 avatar Sep 22 '11 02:09 jm81