-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
complete solution(Shabbir Saifee) #37
base: master
Are you sure you want to change the base?
complete solution(Shabbir Saifee) #37
Conversation
if @url.destroy | ||
redirect_to urls_path | ||
else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destroy
doesn't return true or false to tell you whether it succeeded, like some other ActiveRecord methods. So, just redirect unconditionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh Thanks. Is it better if implement the error handling here? because, if destroy fails due to some DB issue it will raise an exception right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question. The destroy
call can raise an error for many various reasons. I would not handle those errors in app code as long as we don't expect them from regular app usage. Make sure the app is connected with some error aggregation service, then let "exceptional" exceptions go uncaught.
If we start seeing errors we didn't account for, that's when we should do what we can to prevent them and also rescue them to return a more user-friendly response to our user.
puts "inside hit_url" | ||
url = Url.find_by short_url: params[:short_url] | ||
if url | ||
url.update('click_count' => url.click_count + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concurrent clicks will be undercounted. Not that it really matters for this exercise, but I think it's a fun exercise to think about doing atomic updates to the database records.
@jaybobo