Reputation: 310
I have caller ID functionality working for my app but I am currently stumped on how to dynamically update the correct column based on the value of params[:call_number_type]
params[:call_number_type]
can be "alt_phone"
, "cell_phone"
, "office_phone"
, or nil
... nil defaulting to "alt_phone"
would be ideal.
Each of the above strings corresponds to a column name that I need to update if params[:call_number_type]
has that value.
@contact = Contact.find(params[:contact_id])
if @contact.update(this_needs_to_be_the_right_column_key: params[:call_number])
The above update statement would have to be dynamically created based on the value of params[:call_number_type]
If some one could help me out that would be great. Thanks.
Upvotes: 1
Views: 159
Reputation: 4639
Try this
if @contact.update(call_number_type => params[:call_number])
...
private
def call_number_type
params[:call_number_type].present? ? params[:call_number_type] : :alt_phone
end
Upvotes: 1