I have a table SubscriberProperty which has columns (name, type, account_id, category, mask, contact , mode )
How can i write a Arel condition on the table which takes into account user input like if user has entered name then i should filter on name otherwise not
subs = SubscriberPropertyType.arel_table
SubscriberProperty.where(sub[:name].eq(name))
if the user has entered mode then it should also filter on mode
mode = {mode entered by user}
SubscriberProperty.where(sub[:mode].eq(mode))
How can i combine above two conditions based on the fact it depends whether the user has entered the particular field or not
You can keep chaining your conditions, if this is in a controller I usually do it like this:
Arel seems unnecessary, but it is exactly the same logic, could be useful if you're planning on using other operators than
eq: