Skip to content

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