refactored missing link scenario to make more sense
+ 404 code, stay on the current page, and load the form + also simplified the logic for the create action if the link doesn't already existpull/18/head
parent
c7fee27623
commit
5bce31baf2
11
app.rb
11
app.rb
|
|
@ -19,11 +19,10 @@ class App < Roda
|
|||
|
||||
r.get String do | url_code |
|
||||
link = links.filter(:code => url_code)
|
||||
if link.first.nil?
|
||||
flash['message'] = "Link #{url_code} doesn't exist"
|
||||
r.redirect '/'
|
||||
end
|
||||
r.redirect link.first[:url]
|
||||
r.redirect link.first[:url] unless link.first.nil?
|
||||
@message = "Link #{url_code} doesn't exist"
|
||||
response.status = 404
|
||||
view :home
|
||||
end
|
||||
|
||||
r.post "create" do
|
||||
|
|
@ -32,7 +31,7 @@ class App < Roda
|
|||
flash['message'] = "Please enter a valid URL";
|
||||
r.redirect '/'
|
||||
end
|
||||
if nil == links.filter(:url => url).first
|
||||
if links.filter(:url => url).first.nil?
|
||||
code = SecureRandom.urlsafe_base64 4
|
||||
links.insert(url: url, code: code)
|
||||
@message = "Link created"
|
||||
|
|
|
|||
Loading…
Reference in New Issue