Kumar Nikhil
Kumar Nikhil

Reputation: 125

Ruby On Rails Case sensitive string

I have params[:location] that should accept Left PA and Right PA it should not matter if we pass PA Left, Pa LEFT, Pa left, pa left, etc. I have to convert it to Left PA and similar with Right PA.

if params[:source] == 'abc'
  'ABC'
elsif params[:source] == 'DEF'
  'DEF'
else
  params[:source]
end

Can someone help me.

Upvotes: 0

Views: 51

Answers (1)

Amol Mohite
Amol Mohite

Reputation: 642

you can use downcase/upcase method to compare. And instead of if/else you can use case

case params[:location].to_s.downcase
  when 'pa left'
    'Left PA'
  when 'pa right'
    'Right PA'
  else 
    params[:location]
end

Upvotes: 1

Related Questions