I have the following rails grape api endpoint in the users resource:
desc 'updates a user'
params do
optional :first_name, type: String
optional :active, type: Boolean
optional :second_name, type: String
optional :rating, type: Integer
requires :id, type: Integer
end
put ':id' do
user = User.find_or_create_by(id: params[:id])
user.name = params[:name] if params[:name].present?
user.active = params[:active] if params[:active].present?
user.second_name = params[:second_name] if params[:second_name].present?
user.rating = params[:rating] if params[:actratingve].present?
user.save!
end
Any nicer way to update model without asking per line if the param is present?