-
Notifications
You must be signed in to change notification settings - Fork 9
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
Duplicate error messages on User objects #12
Comments
Dating back to a discussion a while ago, I am still not a fan of the design decision to even have Nevertheless, this The gem is pulling these values by checking If that's the case, one "solution" to your problem is to just reuse that instance variable name instead of a different Another option is to potentially try the gem with calling assigns.values.select {|o| o.respond_to?(:errors) && o.errors.is_a?(ActiveModel::Errors) }.uniq This would generally handle any case where you re-assign an instance variable that may also be present, not just for this common Another potential option is to extend the API with an I am definitely against introducing a hardcoded list of instance variable names that we exclude ( I am also against having this gem pulling a list of model names dynamically from |
Yeah, you make some great points. The potential solution I shared isn't perfect and could definitely be problematic in some scenarios. But my goal, however, is perfectly valid. I would like message_block to be even easier to install. I don't want to think about which models and flash messages to display. I want it to just show all of them... unless and until I require a more selective approach. With convention over configuration in mind, I think this is probably true of most Rails apps. Just show me errors on my stuff without a lot of fuss. So, given that, you've got the selective approach pretty well covered. Let's work on improving support for the zero-config approach. :) PS: Indeed, it looks like sorcery is creating an instance variable for
I'll think about this some more and get back to you. |
I ran into this duplicate flash message bug again, googled around, and rediscovered this issue. LOL. So... five years later, here's how I fixed it:
This removes any duplicate |
My app is using message_block to show all errors and flash messages.
So I've got this in my application layout:
= message_block on: :all
It's been working great... with one exception. When I try to update my password while being logged in, if there is a validation error, the error output appears twice:
It took me a long time to figure out why this was happening. But I finally did.
When I try to change my password while I'm logged in, there are actually two instances of the
User
model loaded by the view.One is an instance of
current_user
(the convenience method used by most Rails authentication gems as a proxy for a logged in user). The other is a more generic instance of theUser
model -- accessed via@user
-- that I'm using to update the password.And, yes,
@user
is really a copy ofcurrent_user
, but there are still technically twoUser
objects being loaded in the view.Here are the relevant bits of the controller for reference
One way to fix this would be to reject the current_user object from the list of objects that are checked for errors in the
message_block
helper.But, ultimately, I think a better approach for the
:all
option would be to grab every user model from theapp/models
directory -- which is how we're doing it with Graffletopia, albeit as an initializer.Thoughts?
The text was updated successfully, but these errors were encountered: