-
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
Hari's solution #36
base: master
Are you sure you want to change the base?
Hari's solution #36
Conversation
def route_me | ||
url = Url.find_by_short_url params[:short_url] | ||
|
||
if url.nil? |
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.
I prefer if url
(drop .nil?
) to phrase things positively, and put the "happy path" code in the top of the if/else
.
if url.nil? | ||
redirect_to root_path | ||
else | ||
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.
ActiveRecord has a method for this kind of thing.
There's a subtle bug as currently written. Do you see it?
|
||
def long_url_responds | ||
link = URI.parse(long_url) | ||
if link.is_a?(URI::HTTP) || link.is_a?(URI::HTTPS) |
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.
This bit seems very similar to long_url.start_with? 'http://', 'https://'
in the above method. I think a concept is duplicated here. 🤔
@jaybobo