Query help


#1

Hi…
Any ways to optimise this conditions using ternery operator

if params[:userinfo]
if params[:userinfo][:company_id] == nil or
params[:userinfo][:company_id]
== “Select Company”
company_id = nil
else
company_id = params[:userinfo][:company_id]

end

if params[:userinfo][:department_id] == nil or
params[:userinfo][:department_id] == “Select Department” or
params[:userinfo][:department_id] == “Any Department”
department_id = nil
else
department_id = params[:userinfo][:department_id]
end
if params[:userinfo][:role_id] == nil or
params[:userinfo][:role_id] == “Select Role” or
params[:userinfo][:role_id] == “Any Role”
role_id = nil
puts “here”
else
role_id = params[:userinfo][:role_id]
puts “els”
end
online_status = params[:userinfo][:online_status]

end


#2

Newb N. wrote:

Hi…
Any ways to optimise this conditions using ternery operator

if params[:userinfo]
if params[:userinfo][:company_id] == nil or
params[:userinfo][:company_id]
== “Select Company”

As the first of a great many minor issues with this code, you can DRY it
by
stashing each parameter as you ‘if’ it…

if userinfo = params[:userinfo]
if (company_id = userinfo[:company_id]) == nil or
company_id == ‘Select Company’

…but there are also major issues. Your options should use an
id in
their value=’’ attributes, and the one for ‘Select Company’ should be
nil…