Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shabbirsaifee92
Copy link

@shabbirsaifee92 shabbirsaifee92 changed the title complete solution complete solution(Shabbir Saifee) Feb 23, 2018
if @url.destroy
redirect_to urls_path
else

Copy link
Member

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.

Copy link
Author

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?

Copy link
Member

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)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants