Forum: Ruby on Rails simple if then question?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
NeoWip (Guest)
on 2007-04-28 22:41
(Received via mailing list)
I need to do a if field value = 1 then method but I cannot seem to
find the right way /sytax for it.

I have a rule table which contains a selector_id field. If set to 1
then do A else do B.

No matter what type of syntax I try I cannot seem to get it working.
Anyone that can help out?
Jarod R. (Guest)
on 2007-04-28 22:46
(Received via mailing list)
NeoWip wrote:
> >
>
>
if (field_value == 1)
    do stuff
else
    do different stuff
end

Make sure you use a double =  when comparing values.
NeoWip (Guest)
on 2007-04-28 23:03
(Received via mailing list)
I still get a NameError in RulesController#learnif

The table name is rules, model name rule and the field is
selector_id.

Here is what I have
    if (selector_id == 1)
      @rules = 'test'
    else
      @rules = 'works'

what am I doing wrong?
NeoWip (Guest)
on 2007-04-29 01:36
(Received via mailing list)
got it

    t = Rule.find(1)
    if ( t.selector_id == 2)
      @rules = 'test'
    else
      @rules = 'works'
This topic is locked and can not be replied to.