added logic to prevent duplicate url's from being entered, it just
fetches the url and load it insteadpull/6/head
parent
935b0c5a9f
commit
47f8741592
6
app.rb
6
app.rb
|
|
@ -19,8 +19,10 @@ class App < Roda
|
|||
|
||||
r.post "create" do
|
||||
url = r.params['url']
|
||||
code = SecureRandom.urlsafe_base64 4
|
||||
links.insert(url: url, code: code)
|
||||
if nil == links.filter(:url => url).first
|
||||
code = SecureRandom.urlsafe_base64 5
|
||||
links.insert(url: url, code: code)
|
||||
end
|
||||
@new_link = 'http://' + request.env['HTTP_HOST'] + '/' + links.filter(:url => url).first[:code]
|
||||
view :create
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue