AA
Joined 10/28/2018
AA said over 5 years ago on Refactoring Models :
Hello, Sorry for the question, but can you explain why you've constructed a loop with the `loop` statement for the token generation? If I'm not mistaken the `token` *value* of the hash parameter of the `exists?` method refers to `self.token` so basically the `token` attribute (i.e. column or method) of the current object being created (which is an in-memory object at that moment). I also assume that this value is `nil` since this column has no default value and `null` values are allowed. So the first time we presumably do not yet have any Users in the database with a `nil` token. Then the `break` instruction will not be executed, resulting to a second iteration for the loop, after a random token is being set for the in-memory object, right? So in the next iteration, we have a `token` value and we will `break` before setting another token if there are an existing user with that same token, am I still right? Then if not, we will continue like this again and again... And if so, we will end up with two users having the same token. Sorry for my bad English, but I hope my explanation makes sense... Can you explain what I misunderstood? Thank you. *(Thanks too for the videos!)*

AA said over 5 years ago on Refactoring Models :
So why not simply use an `until` loop, like so? ``` until self.class.exists?(token: token) self.token = SecureRandom.hex end ``` Thank you

AA said over 5 years ago on Refactoring Models :
I've started to read about the POODR book.. And indeed, it seems a better approach instead of simply modules... But since I'm new, I don't see yet how to figure out the abstraction/decomposition...

AA said over 5 years ago on Refactoring Models :
Hi, Thank you for the quick reply... But isn't nil at the first time, so the loop is always entered at least once?

AA said about 5 years ago on Stimulus Javascript Framework :
Hi, I've heard about Stimulus being a good drop-in replacement for jQuery (within rails application) rather than being a competitor to Vue, Angular, etc. It suits my needs because of I already have my HTMLs and I wanted to get rid of jQuery and sprockets etc. My application doesn't have heavy JS features but definitely some kind of DOM manipulation for forms (validation and nested form addition and deletion). Some other use-cases I think of are field formatting (phone numbers with dashes, prices with appropriate currency symbols and spaces, etc.), and also multi-step forms (with JS), so basically like a mini SPA for the multi-step forms only. Will I be able to do this kind of stuff with Stimulus? (again without jQuery) I will refactor my whole UI and I was also thinking about either going with Stimulus or Vue.. Regarding my needs do you have some advises?