diff --git a/.browserslistrc b/.browserslistrc new file mode 100644 index 0000000..e94f814 --- /dev/null +++ b/.browserslistrc @@ -0,0 +1 @@ +defaults diff --git a/.gitignore b/.gitignore index 65e6478..6e58de3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,31 @@ -# See https://help.github.com/articles/ignoring-files for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' - -# Ignore bundler config. -/.bundle - -# Ignore the default SQLite database. -/db/*.sqlite3 -/db/*.sqlite3-journal - -# Ignore all logfiles and tempfiles. -/log/* -!/log/.keep -/tmp -/.idea/* -.idea/.generators -.DS_Store +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/* +!/log/.keep +/tmp +/.idea/* +.idea/.generators +.DS_Store *.pem +public/assets/* +vendor/bundle/* +linkhack.pid + +/public/packs +/public/packs-test +/node_modules +/yarn-error.log +yarn-debug.log* +.yarn-integrity \ No newline at end of file diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..7921bd0 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.4.8 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7e20e18 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM ruby:3.4.8-trixie + +RUN apt-get update -qq && apt-get install -y build-essential apt-utils libpq-dev nodejs +WORKDIR /app +RUN gem install bundler +COPY Gemfile* ./ +RUN bundle install +ADD . /app +EXPOSE 3000 +CMD ["rails","server", "-b", "0.0.0.0"] diff --git a/Gemfile b/Gemfile index f9b0fff..cf74b52 100644 --- a/Gemfile +++ b/Gemfile @@ -1,39 +1,45 @@ source 'https://rubygems.org' - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.0.3' +gem 'rails', '~> 7.1' +gem 'rails-html-sanitizer', '>= 1.6.1' # Use sqlite3 as the database for Active Record -gem 'sqlite3' +gem 'sqlite3', '~> 1.6' # Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0' +gem 'sass-rails', '~> 6.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views -gem 'coffee-rails' +gem 'coffee-rails', '~> 5.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby -gem 'levenshtein-ffi', :require => 'levenshtein' - # Add URL validation gem 'validate_url' -gem 'rack-cors', :require => 'rack/cors' +gem 'importmap-rails' + +gem 'rack', '~> 2.2.13' +gem 'rack-cors', '~> 1.1.0', require: 'rack/cors' # Use jquery as the JavaScript library -gem 'jquery-rails' -# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks' +gem 'jquery-rails', '~> 4.6' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', group: :doc +gem 'sdoc', '~> 2.6', group: :doc gem 'bootstrap-sass' gem 'autoprefixer-rails' +gem 'mini_racer', '~> 0.6.3' +gem 'nokogiri', '>= 1.18.9' gem 'will_paginate' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' +gem 'text' +gem 'rdoc', '>= 6.5.1.1' + +gem 'puma', '~> 6.6' +gem 'listen', '~> 3.8' # Use Unicorn as the app server # gem 'unicorn' @@ -46,7 +52,7 @@ group :development, :test do gem 'byebug' # Access an IRB console on exception pages or by using <%= console %> in views - gem 'web-console' + gem 'web-console', '~> 3.7.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index 9b2701f..500c48d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,214 +1,337 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.6) - actionpack (= 5.0.6) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.6) - actionpack (= 5.0.6) - actionview (= 5.0.6) - activejob (= 5.0.6) + actioncable (7.1.6) + actionpack (= 7.1.6) + activesupport (= 7.1.6) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.1.6) + actionpack (= 7.1.6) + activejob (= 7.1.6) + activerecord (= 7.1.6) + activestorage (= 7.1.6) + activesupport (= 7.1.6) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.1.6) + actionpack (= 7.1.6) + actionview (= 7.1.6) + activejob (= 7.1.6) + activesupport (= 7.1.6) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.0.6) - actionview (= 5.0.6) - activesupport (= 5.0.6) - rack (~> 2.0) - rack-test (~> 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.6) - activesupport (= 5.0.6) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.6) + actionview (= 7.1.6) + activesupport (= 7.1.6) + cgi + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.6) + actionpack (= 7.1.6) + activerecord (= 7.1.6) + activestorage (= 7.1.6) + activesupport (= 7.1.6) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.1.6) + activesupport (= 7.1.6) builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.6) - activesupport (= 5.0.6) + cgi + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.6) + activesupport (= 7.1.6) globalid (>= 0.3.6) - activemodel (5.0.6) - activesupport (= 5.0.6) - activerecord (5.0.6) - activemodel (= 5.0.6) - activesupport (= 5.0.6) - arel (~> 7.0) - activesupport (5.0.6) + activemodel (7.1.6) + activesupport (= 7.1.6) + activerecord (7.1.6) + activemodel (= 7.1.6) + activesupport (= 7.1.6) + timeout (>= 0.4.0) + activestorage (7.1.6) + actionpack (= 7.1.6) + activejob (= 7.1.6) + activerecord (= 7.1.6) + activesupport (= 7.1.6) + marcel (~> 1.0) + activesupport (7.1.6) + base64 + benchmark (>= 0.3) + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - annotate (2.7.2) - activerecord (>= 3.2, < 6.0) - rake (>= 10.4, < 13.0) - arel (7.1.4) - autoprefixer-rails (7.2.5) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + mutex_m + securerandom (>= 0.3) + tzinfo (~> 2.0) + annotate (3.2.0) + activerecord (>= 3.2, < 8.0) + rake (>= 10.4, < 14.0) + autoprefixer-rails (10.2.4.0) execjs - bindex (0.5.0) - bootstrap-sass (3.3.7) + base64 (0.3.0) + benchmark (0.5.0) + bigdecimal (4.0.1) + bindex (0.8.1) + bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) - builder (3.2.3) - byebug (9.1.0) - coffee-rails (4.2.2) + sassc (>= 2.0.0) + builder (3.2.4) + byebug (11.1.3) + cgi (0.5.1) + coffee-rails (5.0.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0) + railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - crass (1.0.3) - diff-lcs (1.3) - erubis (2.7.0) + concurrent-ruby (1.2.2) + connection_pool (3.0.2) + crass (1.0.6) + date (3.5.1) + diff-lcs (1.4.4) + drb (2.2.3) + erb (6.0.1) + erubi (1.12.0) execjs (2.7.0) - ffi (1.9.18) - globalid (0.4.1) - activesupport (>= 4.2.0) - i18n (0.9.3) + ffi (1.17.2-arm64-darwin) + ffi (1.17.2-x86_64-darwin) + ffi (1.17.2-x86_64-linux-gnu) + globalid (1.3.0) + activesupport (>= 6.1) + i18n (1.14.1) concurrent-ruby (~> 1.0) - jbuilder (2.7.0) - activesupport (>= 4.2.0) - multi_json (>= 1.2) - jquery-rails (4.3.1) + importmap-rails (2.1.0) + actionpack (>= 6.0.0) + activesupport (>= 6.0.0) + railties (>= 6.0.0) + io-console (0.8.2) + irb (1.16.0) + pp (>= 0.6.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.11.2) + activesupport (>= 5.0.0) + jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.6) - levenshtein-ffi (1.1.0) - ffi (~> 1.9) - loofah (2.1.1) + libv8-node (16.10.0.0-arm64-darwin) + libv8-node (16.10.0.0-x86_64-darwin) + libv8-node (16.10.0.0-x86_64-darwin-19) + libv8-node (16.10.0.0-x86_64-linux) + listen (3.8.0) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + logger (1.7.0) + loofah (2.25.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.0) + nokogiri (>= 1.12.0) + mail (2.9.0) + logger mini_mime (>= 0.1.1) - method_source (0.9.0) - mini_mime (1.0.0) - mini_portile2 (2.3.0) - minitest (5.11.1) - multi_json (1.13.1) - nio4r (2.2.0) - nokogiri (1.8.1) - mini_portile2 (~> 2.3.0) - public_suffix (3.0.1) - rack (2.0.3) - rack-cors (1.0.2) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.6) - actioncable (= 5.0.6) - actionmailer (= 5.0.6) - actionpack (= 5.0.6) - actionview (= 5.0.6) - activejob (= 5.0.6) - activemodel (= 5.0.6) - activerecord (= 5.0.6) - activesupport (= 5.0.6) - bundler (>= 1.3.0) - railties (= 5.0.6) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + net-imap + net-pop + net-smtp + marcel (1.1.0) + mini_mime (1.1.5) + mini_portile2 (2.8.8) + mini_racer (0.6.3) + libv8-node (~> 16.10.0.0) + minitest (5.18.1) + mutex_m (0.3.0) + net-imap (0.6.2) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.1) + net-protocol + nio4r (2.5.9) + nokogiri (1.19.0-arm64-darwin) + racc (~> 1.4) + nokogiri (1.19.0-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.19.0-x86_64-linux-gnu) + racc (~> 1.4) + pp (0.6.3) + prettyprint + prettyprint (0.2.0) + psych (5.3.1) + date + stringio + public_suffix (4.0.6) + puma (6.6.1) + nio4r (~> 2.0) + racc (1.7.1) + rack (2.2.21) + rack-cors (1.1.1) + rack (>= 2.0.0) + rack-session (1.0.2) + rack (< 3) + rack-test (2.1.0) + rack (>= 1.3) + rackup (1.0.1) + rack (< 3) + webrick + rails (7.1.6) + actioncable (= 7.1.6) + actionmailbox (= 7.1.6) + actionmailer (= 7.1.6) + actionpack (= 7.1.6) + actiontext (= 7.1.6) + actionview (= 7.1.6) + activejob (= 7.1.6) + activemodel (= 7.1.6) + activerecord (= 7.1.6) + activestorage (= 7.1.6) + activesupport (= 7.1.6) + bundler (>= 1.15.0) + railties (= 7.1.6) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.6) - actionpack (= 5.0.6) - activesupport (= 5.0.6) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.3.0) - rb-fsevent (0.10.2) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) - rdoc (4.3.0) - rspec (3.7.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-core (3.7.1) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + rails-html-sanitizer (1.6.2) + loofah (~> 2.21) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (7.1.6) + actionpack (= 7.1.6) + activesupport (= 7.1.6) + cgi + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) + zeitwerk (~> 2.6) + rake (13.0.6) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) + ffi (~> 1.0) + rdoc (7.0.3) + erb + psych (>= 4.0.0) + tsort + reline (0.6.3) + io-console (~> 0.5) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.0) - sass (3.5.5) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - sdoc (0.4.2) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) - spring (2.0.2) - activesupport (>= 4.2) - sprockets (3.7.1) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + sdoc (2.6.1) + rdoc (>= 5.0) + securerandom (0.4.1) + spring (2.1.1) + sprockets (4.2.0) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.3.13) - thor (0.20.0) - thread_safe (0.3.6) - tilt (2.0.8) - turbolinks (5.1.0) - turbolinks-source (~> 5.1) - turbolinks-source (5.1.0) - tzinfo (1.2.4) - thread_safe (~> 0.1) - uglifier (4.1.4) + sqlite3 (1.6.0) + mini_portile2 (~> 2.8.0) + stringio (3.2.0) + text (1.3.1) + thor (1.2.2) + tilt (2.0.11) + timeout (0.6.0) + tsort (0.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) - validate_url (1.0.2) + validate_url (1.0.13) activemodel (>= 3.0.0) - addressable - web-console (3.5.1) + public_suffix + web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.6.5) + webrick (1.9.2) + websocket-driver (0.8.0) + base64 websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) - will_paginate (3.1.6) + websocket-extensions (0.1.5) + will_paginate (3.3.0) + zeitwerk (2.6.8) PLATFORMS - ruby + arm64-darwin-22 + arm64-darwin-23 + arm64-darwin-24 + x86_64-darwin-19 + x86_64-darwin-20 + x86_64-linux DEPENDENCIES annotate autoprefixer-rails bootstrap-sass byebug - coffee-rails + coffee-rails (~> 5.0.0) + importmap-rails jbuilder (~> 2.0) - jquery-rails - levenshtein-ffi - rack-cors - rails (~> 5.0.3) + jquery-rails (~> 4.6) + listen (~> 3.8) + mini_racer (~> 0.6.3) + nokogiri (>= 1.18.9) + puma (~> 6.6) + rack (~> 2.2.13) + rack-cors (~> 1.1.0) + rails (~> 7.1) + rails-html-sanitizer (>= 1.6.1) + rdoc (>= 6.5.1.1) rspec - sass-rails (~> 5.0) - sdoc (~> 0.4.0) + sass-rails (~> 6.0) + sdoc (~> 2.6) spring - sqlite3 - turbolinks + sqlite3 (~> 1.6) + text uglifier (>= 1.3.0) validate_url - web-console + web-console (~> 3.7.0) will_paginate BUNDLED WITH - 1.15.4 + 2.5.17 diff --git a/README.md b/README.md index 4e53758..b13af10 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,31 @@ A simple link shortener designed to run on an internal network to share resources and provide easy references to specific items within a domain. At the moment it supports super basic parameterization and not much else. +# Development + +## Getting started + +``` +bin/bundle install +bin/rails db:create +bin/rails db:schema:load +``` + +## Running specs + +Make sure your local environment is set up, see "Getting started". + +``` +bin/bundle exec rspec +``` + ## Future Work There are loads of things I'd like to make LinkHack do, and ultimately there are probably a whole whack of ideas that other people are going to have that are way better than anything I come up with. So I'll maintain a list here of my personal favourites both to give a sense of where this is going, and so that those that are interested in contributing have some suggestions if they don't have anything specific in mind. +- Dockerize the application - Link pagination. Seems like it might be useful eventually. - Slack integration. Still working out exactly how to do this, but it'd be great if go/foo turned into a clickable link in slack. There are some other things that could be built (or just configured in slack) as well, like link creation through /commands and inline previews. - Chrome search engine integration. I've heard that you can make it so that chrome can do intelligent autocompleting if you set up the correct endpoint for it to discover. I'll need to figure out how this works. - Better documentation. Sorry. - More robust/intelligent parameterization. I've got some ideas for this but I'm totally open to suggestions. -- Better handling of redirect loops. +- Better handling of redirect loops. diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..ffbd8c0 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,4 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css +//= link_tree ../../javascript .js +//= link_tree ../../../vendor/javascript .js \ No newline at end of file diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b9e4ee5..67cab93 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,5 @@ // //= require jquery //= require jquery_ujs -//= require turbolinks //= require bootstrap-sprockets //= require_tree . diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9a98060..52acdba 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,11 +13,13 @@ def redirector relevant_links = Link .levenshtein_distances(short) .sort_by(&:distance) - link = relevant_links.first.link if relevant_links.first.distance < 2 + if relevant_links.first.present? && relevant_links.first.distance < 2 + link = relevant_links.first.link + end end if link.present? - redirect_to link.url_for fullpath + redirect_to link.url_for(fullpath), allow_other_host: true else redirect_to( controller: :links, diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index fcda4e2..5510a8b 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -13,14 +13,18 @@ def show end def new - return unless params.member? :link + return unless params.key? :link - @relevant_links = Link - .levenshtein_distances(link_params[:shortlink]) - .sort_by(&:distance) - .reject { |link| link.distance > 5} - .first(5) - .map(&:link) + if link_params[:shortlink].present? + @relevant_links = Link + .levenshtein_distances(link_params[:shortlink]) + .sort_by(&:distance) + .reject { |link| link.distance > 5} + .first(5) + .map(&:link) + else + @relevant_links = [] + end @link = Link.new(link_params) end @@ -53,10 +57,15 @@ def destroy private def load_link + params.permit(:id, :link) @link = Link.find params[:id] end def link_params - params.require(:link).permit(:url, :shortlink, :argsstr, :description, :type) + if params[:link].present? + params.require(:link).permit(:url, :shortlink, :argsstr, :description, :type) + else + params.permit(:url, :shortlink, :argsstr, :description, :type) + end end end diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 0000000..4054010 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1,9 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "jquery" +import "bootstrap" + +// Add jQuery to global scope for legacy code +window.jQuery = jQuery; +window.$ = jQuery; + +console.log('Hello World from Importmap') \ No newline at end of file diff --git a/app/models/link.rb b/app/models/link.rb index 2a43e7a..c1d9d4b 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,5 +1,4 @@ require 'uri' -require 'levenshtein' class Link < ActiveRecord::Base validates :shortlink, presence: true, uniqueness: true @@ -16,7 +15,7 @@ def self.search(query) def self.levenshtein_distances(query) links = where(type: nil) links.map do |link| - OpenStruct.new link: link, distance: Levenshtein.distance(link.shortlink, query) + OpenStruct.new link: link, distance: Text::Levenshtein.distance(link.shortlink, query) end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 20a167e..a4ef4b4 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,9 +2,9 @@ Linkhack - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= stylesheet_link_tag 'application', media: 'all' %> <%= csrf_meta_tags %> + <%= javascript_importmap_tags %>