0

I have a Product model which has several columns out of which two columns are :first_name and :last_name.

How would I parameterize value of column B(:last_name) when the value of column A(:first_name) is absent or blank.

I tried two methods below and it did not work.

def to_param
  if :first_name.present?
   "#{id}-#{first_name.parameterize}"
 else
   "#{id}-#{last_name.parameterize}"
end

Method-2:

def to_param
 "#{id}-#{first_name.parameterize}" || "#{id}-#{last_name.parameterize}"
end
Subrat Rout
  • 95
  • 2
  • 16

1 Answers1

1

Seems like a one char fix, just don't use symbol in your first method.

def to_param
  if first_name.present?
   "#{id}-#{first_name.parameterize}"
 else
   "#{id}-#{last_name.parameterize}"
end
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367