-
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
DONE. :D #39
base: master
Are you sure you want to change the base?
DONE. :D #39
Conversation
private | ||
|
||
def set_url | ||
@url = Url.find_by(short_url: params[:short_url]) |
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.
Since this method is only invoked for one controller action, I'd suggest inlining it there.
@url.click_count += 1 | ||
@url.save | ||
|
||
redirect_to "#{@url.long_url}" |
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.
The string interpolation isn't needed here. redirect_to @url.long_url
should do the trick.
end | ||
|
||
def url_params | ||
params.require(:url).permit(:long_url, :short_url) |
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.
We permit setting the short_url
here, but there isn't an input in the form for it, and it will be overwritten in the model. I think short_url
should be removed here.
def create_short_url | ||
begin | ||
short_url = SecureRandom.hex(4) | ||
end while Url.where(short_url: short_url).exists? |
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'm pretty sure Url.exists?(short_url: short_url)
works here too.
|
||
def compliant? | ||
new_uri = URI.parse(self.long_url) | ||
new_uri.is_a?(URI::HTTP) && !new_uri.host.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 thought you had a bug here. Instead, I just learned that URI::HTTPS
is a subclass of URI::HTTP
. 👍
I don't see an implementation for this URL validation yet:
|
@jaybobo
just letting you know. the secret page is a user's profile page.