Sunday, June 10, 2012

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

It is not surprising that you always get :tie if this is the first
line in the method. Go back and look at Michaels code again and pay
attention to newlines. There should be only one 'if' however which
may have confused you. It is important to make sure you understand
code that someone suggests rather than just using it. If you cannot
understand it then work through some Ruby tutorials and if you still
cannot understand it then ask for clarification.

Also both Michael and myself suggested looking at the Rails Guide on
debugging, did you do this? If so what did you learn when you used
those techniques to debug your code?

Colin

>    if if schedule.for.to_i == schedule.against.to_i
>         schedule.for.to_i > schedule.against.to_i ? :win : :lose
>       end
>    end
>
>  end
>
> #view
> <strong><%= win_lose_tie_display(schedule.win_lose_tie) %></strong>
>
> #helper
> def win_lose_tie_display(value)
>    case value
>      when :win
>        "W"
>      when :lose
>        "L"
>      when :tie
>        "T"
>      else
>        "unknown win/lose/tie value"
>    end
>  end
>
> i even tried what you would do in php and had a variable set us :result
> to return though it gave me a value of unknown win/lost
>
> thanks
>
> --
> Posted via http://www.ruby-forum.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.
>

--
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


Real Estate