hi..
what does the below code ?
conditions << "company_id = #{company_id}" unless
company_id.nil?
pls explain.
thank you
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi, The question should be "Why is this bad code?" The answer for your question is that it append the company_id to the conditions there is a company_id. ciao, tom On Feb 2, 7:38 am, Newb Newb <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi.. > what does the below code ? > conditions << "company_id = #{company_id}" unless company_id.nil? > > pls explain. > thank you > -- > Posted viahttp://www.ruby-forum.com/.-- Thomas R. "TomK32" Koll <> http://ananasblau.com just a geek trying to change the world http://github.com/TomK32 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
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
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Newb Newb 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 <select> options should use an id in their value='''' attributes, and the one for ''Select Company'' should be nil... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---