ruby on rails - conditional statements -
I want to do a customized search through a method in my model: One of the search conditions looks like this:
left = param [: left] [: left_id] right = params [: right] [: right_id] status = give_status (left, right) ou & lt; & Lt; "Status_ID_number = # {status}" Paramozes come from two drop down menus. My problem is with setting the value for the condition if I do something like this so that it sets the value correctly from the left parameter: def self.give_status (left, Right) Return end date I would like to set it as below, where the left and right variables are compared and then a fixed return value is specified based on the conditions. Return to Code 2 below, even if I set the left and right set to 1.
def self.give_status (left, right) if left == 1 and right == 1 return 1 and return 2 end end
The problem is that your param return string def self.give_status (left , Right) if left.to_i == 1 and right.to_i == 1 1 and 2 end short form
def self.give_status ( Left, right) left.to_i == 1 & amp; Amp; Right.to_i == 1? 1: 2 end or get it properly in the beginning:
left = param [[left] [: left_id] .to_i right = params [: OK] [: correct_ID] .to_i position = Dostastus (left, right) where & lt; & Lt; "Status_id_number = # {status}" def self.give_status (left, right) left == 1 & amp; Amp; Correct == 1? 1: 2 end
Comments
Post a Comment