On Sun, Mar 11, 2012 at 05:14, Lupu Alexandru Emil wrote:

if false == money_requirement?
self.add_api_error "You do not have enough money"
end
Or should that be "Money enough, you have not. Buy, or buy not, there
is no try!"? :-) Having Yodified a lot of my checks in the dim
distant past, when working in C, and then discovering that cranking up
the warning level would flag "assignment in conditional"s for me, I've
since gone back to the standard, more readable, order.

Anyway....

There's no need for an == at all when checking a boolean. Just use
"if ! money_requirement?". Also, getting into the habit of comparing
against false, will trip you up later when you really just want to
check "falsiness", but what you're checking returns *nil* on a failure
instead of the actual value *false*.

what i am asking you: Is there any way to play with those
notifications and errors without passing through the database?
I'm not sure what you mean by "passing through". As in, you want to
pass them to the user, but don't want to record them in the database,
I presume.

Off the top of my head, what you could do is pass back a wrapper type
that includes the notices and the actual data object, and not record
the wrapper in the db, only the actual data object. Or, attach the
flash and suchlike, only *after* you've done the saving.

That strikes me as a bit of a hack, though. There's bound to be a
more Rails-ish way to do it. Maybe this will serve as a "bump" and
someone will enlighten us. Maybe Rails is smart enough to know,
"don't save the thing called 'flash'"?

-Dave

--
Dave Aronson:  Available Cleared Ruby on Rails Freelancer
(NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at
www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 11, '12 at 9:14a
activeMar 21, '12 at 2:44p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase