Re: [Rails] Re: if else statement
On 10 June 2012 01:12, Paul McGuane <lists@ruby-forum.com> wrote:
> Hi Michael,
> I have tried the code you suggested, though all i seem to get is every
> result as a tie. this is what I have in my
>
> #model
> def win_lose_tie
> return :tie
> if if schedule.for.to_i == schedule.against.to_i
> schedule.for.to_i > schedule.against.to_i ? :win : :lose
> end
> end
>
> end
Hiya,
The code I posted was a rough, un-run, first draft typed straight into
the email client, but even so, I did a little re-arrangement and
DRYing while composing, and left an extraneous "if" on the first line
of win_lose_tie. This is what it should look like (the if condition at
the end of the line is a modifier, or "guard" - not a construct that
PHP supports AFAIK ;-)
def win_lose_tie
return :tie if schedule.for.to_i == schedule.against.to_i
schedule.for.to_i > schedule.against.to_i ? :win : :lose
end
Bear in mind that I haven't run it - so it may need a little
debugging. The intention of my post is that you see more clearly the
direction the code should be heading towards (rather than having huge
logical constructs in your views).
> i even tried what you would do in php and had a variable set us :result
To be honest, I don't really see how "trying in PHP" is going to go
any way to solving a problem you have in Ruby - it's certainly not one
of the first debugging steps I would recommend :-/
--
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home