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

Hari's solution #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Hari's solution #36

wants to merge 4 commits into from

Conversation

hkdahal
Copy link

@hkdahal hkdahal commented Jan 26, 2018

def route_me
url = Url.find_by_short_url params[:short_url]

if url.nil?
Copy link
Member

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

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

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. 🤔

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