From 74e66f2f04b0de610f50a08f09511cd85b4d0962 Mon Sep 17 00:00:00 2001 From: Leslie Kornes Date: Wed, 16 May 2018 16:13:43 -0400 Subject: [PATCH 1/5] Create url table and model. Route root. Create views/urls. --- source/.DS_Store | Bin 0 -> 6148 bytes source/Gemfile | 3 +- source/Gemfile.lock | 109 ++++++++++-------- source/app/assets/javascripts/application.js | 1 + source/app/assets/stylesheets/custom.css.scss | 4 + source/app/models/url.rb | 6 + source/app/views/layouts/_navigation.html.erb | 19 +++ source/app/views/layouts/application.html.erb | 7 +- source/app/views/urls/index.html.erb | 0 source/bin/erubis | 29 +++++ source/bin/htmldiff | 29 +++++ source/bin/ldiff | 29 +++++ source/bin/rackup | 29 +++++ source/bin/rails | 4 - source/bin/rake | 4 - source/bin/rdoc | 29 +++++ source/bin/ri | 29 +++++ source/bin/rspec | 29 +++++ source/bin/sass | 29 +++++ source/bin/sass-convert | 29 +++++ source/bin/scss | 29 +++++ source/bin/sdoc | 29 +++++ source/bin/sdoc-merge | 29 +++++ source/bin/spring | 33 ++++-- source/bin/sprockets | 29 +++++ source/bin/thor | 29 +++++ source/bin/tilt | 29 +++++ source/config/routes.rb | 56 +-------- .../db/migrate/20180516180541_create_urls.rb | 9 ++ source/db/schema.rb | 23 ++++ 30 files changed, 588 insertions(+), 125 deletions(-) create mode 100644 source/.DS_Store create mode 100644 source/app/assets/stylesheets/custom.css.scss create mode 100644 source/app/models/url.rb create mode 100644 source/app/views/layouts/_navigation.html.erb create mode 100644 source/app/views/urls/index.html.erb create mode 100755 source/bin/erubis create mode 100755 source/bin/htmldiff create mode 100755 source/bin/ldiff create mode 100755 source/bin/rackup create mode 100755 source/bin/rdoc create mode 100755 source/bin/ri create mode 100755 source/bin/rspec create mode 100755 source/bin/sass create mode 100755 source/bin/sass-convert create mode 100755 source/bin/scss create mode 100755 source/bin/sdoc create mode 100755 source/bin/sdoc-merge create mode 100755 source/bin/sprockets create mode 100755 source/bin/thor create mode 100755 source/bin/tilt create mode 100644 source/db/migrate/20180516180541_create_urls.rb create mode 100644 source/db/schema.rb diff --git a/source/.DS_Store b/source/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..df43d348503f68dad3247fc0441d01ed19c4cc4e GIT binary patch literal 6148 zcmeHKu};G<6g;<42^6GmFlJ;zVrB_dE5yJ8KLAM!sv4TAw9Hxf2Y!L?;{)KHZJ{_R zD+2VMWM5+6vwasOjsckAW^xJ)0K_bU(H^TUA^lQX(eW(@L?dIAc~+De?_@X)bwC~X z?GDJh+r=H0SY8&v`+LTo;}08FL=QPiEO3t*9zw1;Y;bq$T%2HqO(Wx_k)j98Tt&h4=a@J0-Wqvb@@B2Ih{F2l!YW%nh^jiPM_)I{ z?1*_duMu^1Zj5U_hdC9B!&~*4xTdd9{ut*N;fg38Peflh3#cy0im>JkPgsXMd4d72 zhiCE@cFa|SOO*kaLNxxM1KhJE;=V(z)d6)t9r$uUz7GkDVCu1QXg?jS>=A$%vDpT% z?ax0kkp^Pwv2w^3hH43(qZh(9LLXW{0YVQqlZZ>9VT_C zwK|{= 1.3.0' gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby - +gem 'bootstrap-sass' # 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 @@ -38,4 +38,3 @@ gem 'spring', group: :development # Use debugger # gem 'debugger', group: [:development, :test] gem 'rspec-rails', group: [:development, :test] - diff --git a/source/Gemfile.lock b/source/Gemfile.lock index fcf8b98..a732f56 100644 --- a/source/Gemfile.lock +++ b/source/Gemfile.lock @@ -28,33 +28,40 @@ GEM thread_safe (~> 0.1) tzinfo (~> 1.1) arel (5.0.1.20140414130214) - builder (3.2.2) + autoprefixer-rails (8.5.0) + execjs + bootstrap-sass (3.3.5) + autoprefixer-rails (>= 5.0.0.1) + sass (>= 3.2.19) + builder (3.2.3) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) - coffee-script (2.3.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.8.0) - diff-lcs (1.2.5) + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + diff-lcs (1.3) erubis (2.7.0) - execjs (2.2.1) + execjs (2.7.0) hike (1.2.3) - i18n (0.6.11) - jbuilder (2.2.2) - activesupport (>= 3.0.0, < 5) - multi_json (~> 1.2) - jquery-rails (3.1.2) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + jbuilder (2.6.4) + activesupport (>= 3.0.0) + multi_json (>= 1.2) + jquery-rails (3.1.5) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - json (1.8.1) - mail (2.6.1) - mime-types (>= 1.16, < 3) - mime-types (2.4.1) - minitest (5.4.2) - multi_json (1.10.1) - rack (1.5.2) - rack-test (0.6.2) + json (1.8.6) + mail (2.7.0) + mini_mime (>= 0.1.1) + mini_mime (1.0.0) + minitest (5.11.3) + multi_json (1.13.1) + rack (1.5.5) + rack-test (0.6.3) rack (>= 1.0) rails (4.1.6) actionmailer (= 4.1.6) @@ -71,60 +78,61 @@ GEM activesupport (= 4.1.6) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.3.2) - rdoc (4.1.2) - json (~> 1.4) - rspec-core (3.1.6) - rspec-support (~> 3.1.0) - rspec-expectations (3.1.2) + rake (12.3.1) + rdoc (4.3.0) + rspec-core (3.7.1) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-mocks (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-mocks (3.1.3) - rspec-support (~> 3.1.0) - rspec-rails (3.1.0) + rspec-support (~> 3.7.0) + rspec-rails (3.7.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.1.0) - rspec-expectations (~> 3.1.0) - rspec-mocks (~> 3.1.0) - rspec-support (~> 3.1.0) - rspec-support (3.1.2) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-support (~> 3.7.0) + rspec-support (3.7.1) sass (3.2.19) - sass-rails (4.0.3) + sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) - sass (~> 3.2.0) - sprockets (~> 2.8, <= 2.11.0) + sass (~> 3.2.2) + sprockets (~> 2.8, < 3.0) sprockets-rails (~> 2.0) - sdoc (0.4.1) + sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - spring (1.1.3) - sprockets (2.11.0) + spring (1.7.2) + sprockets (2.12.4) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.2.0) + sprockets-rails (2.3.3) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.9) - thor (0.19.1) - thread_safe (0.3.4) + sqlite3 (1.3.13) + thor (0.20.0) + thread_safe (0.3.6) tilt (1.4.1) - turbolinks (2.4.0) - coffee-rails - tzinfo (1.2.2) + turbolinks (5.1.1) + turbolinks-source (~> 5.1) + turbolinks-source (5.1.0) + tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (2.5.3) - execjs (>= 0.3.0) - json (>= 1.8.0) + uglifier (4.1.10) + execjs (>= 0.3.0, < 3) PLATFORMS ruby DEPENDENCIES + bootstrap-sass coffee-rails (~> 4.0.0) jbuilder (~> 2.0) jquery-rails @@ -136,3 +144,6 @@ DEPENDENCIES sqlite3 turbolinks uglifier (>= 1.3.0) + +BUNDLED WITH + 1.16.1 diff --git a/source/app/assets/javascripts/application.js b/source/app/assets/javascripts/application.js index d6925fa..04c7d4a 100644 --- a/source/app/assets/javascripts/application.js +++ b/source/app/assets/javascripts/application.js @@ -12,5 +12,6 @@ // //= require jquery //= require jquery_ujs +//= require bootstrap-sprockets //= require turbolinks //= require_tree . diff --git a/source/app/assets/stylesheets/custom.css.scss b/source/app/assets/stylesheets/custom.css.scss new file mode 100644 index 0000000..9396934 --- /dev/null +++ b/source/app/assets/stylesheets/custom.css.scss @@ -0,0 +1,4 @@ +$navbar-default-bg: lightblue; + +@import "bootstrap-sprockets"; +@import "bootstrap"; diff --git a/source/app/models/url.rb b/source/app/models/url.rb new file mode 100644 index 0000000..255c78d --- /dev/null +++ b/source/app/models/url.rb @@ -0,0 +1,6 @@ +class Url < ApplicationRecord + + def index + end + +end diff --git a/source/app/views/layouts/_navigation.html.erb b/source/app/views/layouts/_navigation.html.erb new file mode 100644 index 0000000..b808515 --- /dev/null +++ b/source/app/views/layouts/_navigation.html.erb @@ -0,0 +1,19 @@ + diff --git a/source/app/views/layouts/application.html.erb b/source/app/views/layouts/application.html.erb index f946432..98b739f 100644 --- a/source/app/views/layouts/application.html.erb +++ b/source/app/views/layouts/application.html.erb @@ -8,7 +8,12 @@ -<%= yield %> + <%= render 'layouts/navigation' %> + +
+ <%= yield %> + +
diff --git a/source/app/views/urls/index.html.erb b/source/app/views/urls/index.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/source/bin/erubis b/source/bin/erubis new file mode 100755 index 0000000..688963f --- /dev/null +++ b/source/bin/erubis @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'erubis' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("erubis", "erubis") diff --git a/source/bin/htmldiff b/source/bin/htmldiff new file mode 100755 index 0000000..fcb1240 --- /dev/null +++ b/source/bin/htmldiff @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'htmldiff' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("diff-lcs", "htmldiff") diff --git a/source/bin/ldiff b/source/bin/ldiff new file mode 100755 index 0000000..48f40d6 --- /dev/null +++ b/source/bin/ldiff @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'ldiff' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("diff-lcs", "ldiff") diff --git a/source/bin/rackup b/source/bin/rackup new file mode 100755 index 0000000..0f4c5ce --- /dev/null +++ b/source/bin/rackup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rackup' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rack", "rackup") diff --git a/source/bin/rails b/source/bin/rails index 7feb6a3..728cd85 100755 --- a/source/bin/rails +++ b/source/bin/rails @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/source/bin/rake b/source/bin/rake index 8017a02..1724048 100755 --- a/source/bin/rake +++ b/source/bin/rake @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/source/bin/rdoc b/source/bin/rdoc new file mode 100755 index 0000000..5aa2466 --- /dev/null +++ b/source/bin/rdoc @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rdoc' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rdoc", "rdoc") diff --git a/source/bin/ri b/source/bin/ri new file mode 100755 index 0000000..142118a --- /dev/null +++ b/source/bin/ri @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'ri' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rdoc", "ri") diff --git a/source/bin/rspec b/source/bin/rspec new file mode 100755 index 0000000..9c652c5 --- /dev/null +++ b/source/bin/rspec @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/source/bin/sass b/source/bin/sass new file mode 100755 index 0000000..2802b47 --- /dev/null +++ b/source/bin/sass @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'sass' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("sass", "sass") diff --git a/source/bin/sass-convert b/source/bin/sass-convert new file mode 100755 index 0000000..c8a84ec --- /dev/null +++ b/source/bin/sass-convert @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'sass-convert' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("sass", "sass-convert") diff --git a/source/bin/scss b/source/bin/scss new file mode 100755 index 0000000..adbfa6f --- /dev/null +++ b/source/bin/scss @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'scss' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("sass", "scss") diff --git a/source/bin/sdoc b/source/bin/sdoc new file mode 100755 index 0000000..5a58077 --- /dev/null +++ b/source/bin/sdoc @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'sdoc' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("sdoc", "sdoc") diff --git a/source/bin/sdoc-merge b/source/bin/sdoc-merge new file mode 100755 index 0000000..d17e125 --- /dev/null +++ b/source/bin/sdoc-merge @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'sdoc-merge' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("sdoc", "sdoc-merge") diff --git a/source/bin/spring b/source/bin/spring index 253ec37..0791b50 100755 --- a/source/bin/spring +++ b/source/bin/spring @@ -1,18 +1,29 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -# This file loads spring without using Bundler, in order to be fast -# It gets overwritten when you run the `spring binstub` command +# +# This file was generated by Bundler. +# +# The application 'spring' is installed as part of a gem, and +# this file is here to facilitate running it. +# -unless defined?(Spring) - require "rubygems" - require "bundler" +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) - if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) - ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) - ENV["GEM_HOME"] = "" - Gem.paths = ENV +bundle_binstub = File.expand_path("../bundle", __FILE__) - gem "spring", match[1] - require "spring/binstub" +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") end end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("spring", "spring") diff --git a/source/bin/sprockets b/source/bin/sprockets new file mode 100755 index 0000000..510e030 --- /dev/null +++ b/source/bin/sprockets @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'sprockets' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("sprockets", "sprockets") diff --git a/source/bin/thor b/source/bin/thor new file mode 100755 index 0000000..22fe98f --- /dev/null +++ b/source/bin/thor @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'thor' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("thor", "thor") diff --git a/source/bin/tilt b/source/bin/tilt new file mode 100755 index 0000000..dd94b34 --- /dev/null +++ b/source/bin/tilt @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'tilt' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("tilt", "tilt") diff --git a/source/config/routes.rb b/source/config/routes.rb index 3f66539..5fb1316 100644 --- a/source/config/routes.rb +++ b/source/config/routes.rb @@ -1,56 +1,4 @@ Rails.application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end + root 'urls#index' + resources :urls end diff --git a/source/db/migrate/20180516180541_create_urls.rb b/source/db/migrate/20180516180541_create_urls.rb new file mode 100644 index 0000000..5384240 --- /dev/null +++ b/source/db/migrate/20180516180541_create_urls.rb @@ -0,0 +1,9 @@ +class CreateUrls < ActiveRecord::Migration + def change + create_table :urls do |t| + t.text :long_url + t.string :short_url + t.timestamps + end + end +end diff --git a/source/db/schema.rb b/source/db/schema.rb new file mode 100644 index 0000000..d0ce48f --- /dev/null +++ b/source/db/schema.rb @@ -0,0 +1,23 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20180516180541) do + + create_table "urls", force: true do |t| + t.text "long_url" + t.string "short_url" + t.datetime "created_at" + t.datetime "updated_at" + end + +end From 7b89fe6aa52caee4ae2be47d1d96fa9a96ee5de0 Mon Sep 17 00:00:00 2001 From: Leslie Kornes Date: Wed, 16 May 2018 19:55:05 -0400 Subject: [PATCH 2/5] Get jiving. --- source/app/controllers/urls_controller.rb | 22 +++++++++++++++++++ source/app/models/url.rb | 6 +---- source/app/views/urls/index.html.erb | 1 + .../db/migrate/20180516180541_create_urls.rb | 9 -------- .../db/migrate/20180516234423_create_urls.rb | 5 +++++ source/db/schema.rb | 2 +- source/spec/models/url_spec.rb | 5 +++++ 7 files changed, 35 insertions(+), 15 deletions(-) delete mode 100644 source/db/migrate/20180516180541_create_urls.rb create mode 100644 source/db/migrate/20180516234423_create_urls.rb create mode 100644 source/spec/models/url_spec.rb diff --git a/source/app/controllers/urls_controller.rb b/source/app/controllers/urls_controller.rb index ef26710..4951ee8 100644 --- a/source/app/controllers/urls_controller.rb +++ b/source/app/controllers/urls_controller.rb @@ -1,2 +1,24 @@ class UrlsController < ApplicationController + + def index + @urls = Url.all + end + + def new + @url = Url.new + end + + def create + @url = Url.new(url_params) + end + + def show + + end + + private + def url_params + params.require(:recipe).permit(:long_url) + end + end diff --git a/source/app/models/url.rb b/source/app/models/url.rb index 255c78d..e4834ff 100644 --- a/source/app/models/url.rb +++ b/source/app/models/url.rb @@ -1,6 +1,2 @@ -class Url < ApplicationRecord - - def index - end - +class Url < ActiveRecord::Base end diff --git a/source/app/views/urls/index.html.erb b/source/app/views/urls/index.html.erb index e69de29..ce438da 100644 --- a/source/app/views/urls/index.html.erb +++ b/source/app/views/urls/index.html.erb @@ -0,0 +1 @@ +url index diff --git a/source/db/migrate/20180516180541_create_urls.rb b/source/db/migrate/20180516180541_create_urls.rb deleted file mode 100644 index 5384240..0000000 --- a/source/db/migrate/20180516180541_create_urls.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateUrls < ActiveRecord::Migration - def change - create_table :urls do |t| - t.text :long_url - t.string :short_url - t.timestamps - end - end -end diff --git a/source/db/migrate/20180516234423_create_urls.rb b/source/db/migrate/20180516234423_create_urls.rb new file mode 100644 index 0000000..0d8d7bb --- /dev/null +++ b/source/db/migrate/20180516234423_create_urls.rb @@ -0,0 +1,5 @@ +class CreateUrls < ActiveRecord::Migration + def change + + end +end diff --git a/source/db/schema.rb b/source/db/schema.rb index d0ce48f..ceb914f 100644 --- a/source/db/schema.rb +++ b/source/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180516180541) do +ActiveRecord::Schema.define(version: 20180516234423) do create_table "urls", force: true do |t| t.text "long_url" diff --git a/source/spec/models/url_spec.rb b/source/spec/models/url_spec.rb new file mode 100644 index 0000000..495c557 --- /dev/null +++ b/source/spec/models/url_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Url, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From dc5c09162cd6d0148b53d15a0585a090520a503a Mon Sep 17 00:00:00 2001 From: Leslie Kornes Date: Wed, 16 May 2018 23:43:33 -0400 Subject: [PATCH 3/5] Release 0 - Simple Shortener. --- source/Gemfile | 2 ++ source/Gemfile.lock | 6 +++++ source/app/assets/stylesheets/custom.css.scss | 4 ++++ source/app/controllers/urls_controller.rb | 19 ++++++++++++--- source/app/models/url.rb | 8 +++++++ source/app/views/layouts/_messages.html.erb | 10 ++++++++ source/app/views/layouts/_navigation.html.erb | 4 ++-- source/app/views/layouts/application.html.erb | 4 ++-- source/app/views/urls/index.html.erb | 17 +++++++++++++- source/app/views/urls/new.html.erb | 23 +++++++++++++++++++ source/app/views/urls/show.html.erb | 12 ++++++++++ 11 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 source/app/views/layouts/_messages.html.erb create mode 100644 source/app/views/urls/new.html.erb create mode 100644 source/app/views/urls/show.html.erb diff --git a/source/Gemfile b/source/Gemfile index dfb0b18..0e0d323 100644 --- a/source/Gemfile +++ b/source/Gemfile @@ -5,6 +5,7 @@ source 'https://rubygems.org' gem 'rails', '4.1.6' # Use sqlite3 as the database for Active Record gem 'sqlite3' +gem 'pry' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.3' # Use Uglifier as compressor for JavaScript assets @@ -23,6 +24,7 @@ gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring', group: :development diff --git a/source/Gemfile.lock b/source/Gemfile.lock index a732f56..fcb75bd 100644 --- a/source/Gemfile.lock +++ b/source/Gemfile.lock @@ -34,6 +34,7 @@ GEM autoprefixer-rails (>= 5.0.0.1) sass (>= 3.2.19) builder (3.2.3) + coderay (1.1.2) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -57,9 +58,13 @@ GEM json (1.8.6) mail (2.7.0) mini_mime (>= 0.1.1) + method_source (0.9.0) mini_mime (1.0.0) minitest (5.11.3) multi_json (1.13.1) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) @@ -136,6 +141,7 @@ DEPENDENCIES coffee-rails (~> 4.0.0) jbuilder (~> 2.0) jquery-rails + pry rails (= 4.1.6) rspec-rails sass-rails (~> 4.0.3) diff --git a/source/app/assets/stylesheets/custom.css.scss b/source/app/assets/stylesheets/custom.css.scss index 9396934..9357698 100644 --- a/source/app/assets/stylesheets/custom.css.scss +++ b/source/app/assets/stylesheets/custom.css.scss @@ -2,3 +2,7 @@ $navbar-default-bg: lightblue; @import "bootstrap-sprockets"; @import "bootstrap"; + +.form-horizontal { + margin-top: 75px; +} diff --git a/source/app/controllers/urls_controller.rb b/source/app/controllers/urls_controller.rb index 4951ee8..45791f0 100644 --- a/source/app/controllers/urls_controller.rb +++ b/source/app/controllers/urls_controller.rb @@ -1,7 +1,9 @@ class UrlsController < ApplicationController def index - @urls = Url.all + if Url.all.count > 0 + @urls = Url.all + end end def new @@ -10,15 +12,26 @@ def new def create @url = Url.new(url_params) + if validate_url? + flash.now[:danger] = "Check your URL. . ." + render 'new' + else + @url.save + flash.now[:success] = "Your URL is SHORT" + redirect_to url_path(@url) + end end def show - + @url = Url.find(params[:id]) end private def url_params - params.require(:recipe).permit(:long_url) + params.require(:url).permit(:long_url) end + def validate_url? + @url.long_url.exclude?(".com") && @url.long_url.exclude?(".org") && @url.long_url.exclude?(".net") + end end diff --git a/source/app/models/url.rb b/source/app/models/url.rb index e4834ff..6cb081b 100644 --- a/source/app/models/url.rb +++ b/source/app/models/url.rb @@ -1,2 +1,10 @@ class Url < ActiveRecord::Base + before_save :trim_url + + private + + def trim_url + self.short_url = SecureRandom.hex(3) + end + end diff --git a/source/app/views/layouts/_messages.html.erb b/source/app/views/layouts/_messages.html.erb new file mode 100644 index 0000000..c69964c --- /dev/null +++ b/source/app/views/layouts/_messages.html.erb @@ -0,0 +1,10 @@ +
+
+ <% flash.each do |name, msg| %> +
+ × + <%= msg %> +
+ <% end %> +
+
diff --git a/source/app/views/layouts/_navigation.html.erb b/source/app/views/layouts/_navigation.html.erb index b808515..548f6fb 100644 --- a/source/app/views/layouts/_navigation.html.erb +++ b/source/app/views/layouts/_navigation.html.erb @@ -8,11 +8,11 @@ - Snip this! diff --git a/source/app/views/layouts/application.html.erb b/source/app/views/layouts/application.html.erb index 98b739f..8124a0b 100644 --- a/source/app/views/layouts/application.html.erb +++ b/source/app/views/layouts/application.html.erb @@ -9,10 +9,10 @@ <%= render 'layouts/navigation' %> - + <%= render 'layouts/messages' %>
<%= yield %> - +
diff --git a/source/app/views/urls/index.html.erb b/source/app/views/urls/index.html.erb index ce438da..4f54762 100644 --- a/source/app/views/urls/index.html.erb +++ b/source/app/views/urls/index.html.erb @@ -1 +1,16 @@ -url index +

URL too long? Snip it.

+

Check these out.

+
+ + + + + + <% @urls.each do |url| %> + + + + + <% end %> +
Long UrlShort Url
<%= url.long_url %><%= link_to url.short_url, "http://#{url.long_url}" %>
+
diff --git a/source/app/views/urls/new.html.erb b/source/app/views/urls/new.html.erb new file mode 100644 index 0000000..968ea8f --- /dev/null +++ b/source/app/views/urls/new.html.erb @@ -0,0 +1,23 @@ +
+
+ <%= form_for(@url, :html => { class: "form-horizontal", role: "form" }) do |f| %> +
+
+ <%= f.label :long_url %> +
+
+ <%= f.text_field :long_url, class: "form-control", placeholder: "your-long-url.com", + autofocus: true %> +
+
+
+
+ <%= f.submit class: "btn btn-primary" %> +
+
+ <% end %> +
+ [ <%= link_to "Cancel and go home", root_path %> ] +
+
+
diff --git a/source/app/views/urls/show.html.erb b/source/app/views/urls/show.html.erb new file mode 100644 index 0000000..b8c9374 --- /dev/null +++ b/source/app/views/urls/show.html.erb @@ -0,0 +1,12 @@ +
+ + + + + + + + + +
Long UrlShort Url
<%= @url.long_url %><%= link_to @url.short_url, "http://#{@url.long_url}" %>
+
From 9bd3f47d253892f866704c4886629921f532e863 Mon Sep 17 00:00:00 2001 From: Leslie Kornes Date: Thu, 17 May 2018 16:32:24 -0400 Subject: [PATCH 4/5] Release 1: I did add some unnecessary styling while taking a break from the logic. --- source/app/assets/stylesheets/custom.css.scss | 2 +- source/app/controllers/urls_controller.rb | 37 ++++++++++++++----- source/app/models/url.rb | 9 ++--- source/app/views/layouts/_messages.html.erb | 2 +- source/app/views/urls/home.html.erb | 11 ++++++ source/app/views/urls/index.html.erb | 4 +- source/app/views/urls/show.html.erb | 5 ++- source/config/routes.rb | 5 ++- .../20180517042243_add_click_count_to_urls.rb | 5 +++ ...17190422_change_default_for_click_count.rb | 5 +++ source/db/schema.rb | 3 +- 11 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 source/app/views/urls/home.html.erb create mode 100644 source/db/migrate/20180517042243_add_click_count_to_urls.rb create mode 100644 source/db/migrate/20180517190422_change_default_for_click_count.rb diff --git a/source/app/assets/stylesheets/custom.css.scss b/source/app/assets/stylesheets/custom.css.scss index 9357698..b36f7e6 100644 --- a/source/app/assets/stylesheets/custom.css.scss +++ b/source/app/assets/stylesheets/custom.css.scss @@ -3,6 +3,6 @@ $navbar-default-bg: lightblue; @import "bootstrap-sprockets"; @import "bootstrap"; -.form-horizontal { +.form-horizontal, .jumbotron { margin-top: 75px; } diff --git a/source/app/controllers/urls_controller.rb b/source/app/controllers/urls_controller.rb index 45791f0..9990a85 100644 --- a/source/app/controllers/urls_controller.rb +++ b/source/app/controllers/urls_controller.rb @@ -1,7 +1,11 @@ class UrlsController < ApplicationController + before_action :set_url, only: [:show] def index - if Url.all.count > 0 + if Url.all.size == 0 + flash[:danger] = "There aren't any yet. Why don't you start us off?" + render 'home' + else @urls = Url.all end end @@ -12,18 +16,29 @@ def new def create @url = Url.new(url_params) - if validate_url? - flash.now[:danger] = "Check your URL. . ." - render 'new' + #if check_url? + #flash.now[:danger] = "Check your URL. . ." + #render 'new' + #else + #@url.save + #flash.now[:success] = "Your URL is SHORT" + #redirect_to new_url_path(@url) + #end + if @url.save + redirect_to urls_path else - @url.save - flash.now[:success] = "Your URL is SHORT" - redirect_to url_path(@url) + flash.now[:danger] = "Something went wrong with your URL. . ." + render 'new' end end def show - @url = Url.find(params[:id]) + @url.click_count += 1 + @url.save + redirect_to "http://#{@url.long_url}" + end + + def home end private @@ -31,7 +46,11 @@ def url_params params.require(:url).permit(:long_url) end - def validate_url? + def check_url? @url.long_url.exclude?(".com") && @url.long_url.exclude?(".org") && @url.long_url.exclude?(".net") end + + def set_url + @url = Url.find_by(short_url: params[:short_url]) + end end diff --git a/source/app/models/url.rb b/source/app/models/url.rb index 6cb081b..a1103e8 100644 --- a/source/app/models/url.rb +++ b/source/app/models/url.rb @@ -1,10 +1,9 @@ class Url < ActiveRecord::Base - before_save :trim_url + before_create :trim_url private - - def trim_url - self.short_url = SecureRandom.hex(3) - end + def trim_url + self.short_url = SecureRandom.hex(3) + end end diff --git a/source/app/views/layouts/_messages.html.erb b/source/app/views/layouts/_messages.html.erb index c69964c..743c387 100644 --- a/source/app/views/layouts/_messages.html.erb +++ b/source/app/views/layouts/_messages.html.erb @@ -1,7 +1,7 @@
<% flash.each do |name, msg| %> -
+
× <%= msg %>
diff --git a/source/app/views/urls/home.html.erb b/source/app/views/urls/home.html.erb new file mode 100644 index 0000000..5ee40d7 --- /dev/null +++ b/source/app/views/urls/home.html.erb @@ -0,0 +1,11 @@ +
+

URL too long? Snip it.

+
+
+ <%= link_to "Create A Shorty", new_url_path, class: "btn btn-primary" %> +
+
+ <%= link_to "View Existing URLs", urls_path, class: "btn btn-primary" %> +
+
+
diff --git a/source/app/views/urls/index.html.erb b/source/app/views/urls/index.html.erb index 4f54762..ebe6ee8 100644 --- a/source/app/views/urls/index.html.erb +++ b/source/app/views/urls/index.html.erb @@ -5,11 +5,13 @@ Long Url Short Url + Clicks <% @urls.each do |url| %> <%= url.long_url %> - <%= link_to url.short_url, "http://#{url.long_url}" %> + <%= link_to url.short_url, short_url_path(url.short_url) %> + <%= url.click_count %> <% end %> diff --git a/source/app/views/urls/show.html.erb b/source/app/views/urls/show.html.erb index b8c9374..8619451 100644 --- a/source/app/views/urls/show.html.erb +++ b/source/app/views/urls/show.html.erb @@ -3,10 +3,13 @@ Long Url Short Url + Click Count <%= @url.long_url %> - <%= link_to @url.short_url, "http://#{@url.long_url}" %> + <%= link_to "localhost:3000/urls/#{@url.short_url}", url_path(@url) %> + <%= @url.click_count %> +
diff --git a/source/config/routes.rb b/source/config/routes.rb index 5fb1316..0819e28 100644 --- a/source/config/routes.rb +++ b/source/config/routes.rb @@ -1,4 +1,7 @@ Rails.application.routes.draw do - root 'urls#index' + root 'urls#home', only: [:index, :new, :create] + get '/url/:short_url', to: 'urls#show', as: "short_url" + resources :urls + end diff --git a/source/db/migrate/20180517042243_add_click_count_to_urls.rb b/source/db/migrate/20180517042243_add_click_count_to_urls.rb new file mode 100644 index 0000000..8e0eda3 --- /dev/null +++ b/source/db/migrate/20180517042243_add_click_count_to_urls.rb @@ -0,0 +1,5 @@ +class AddClickCountToUrls < ActiveRecord::Migration + def change + add_column :urls, :click_count, :integer + end +end diff --git a/source/db/migrate/20180517190422_change_default_for_click_count.rb b/source/db/migrate/20180517190422_change_default_for_click_count.rb new file mode 100644 index 0000000..0505b35 --- /dev/null +++ b/source/db/migrate/20180517190422_change_default_for_click_count.rb @@ -0,0 +1,5 @@ +class ChangeDefaultForClickCount < ActiveRecord::Migration + def change + change_column :urls, :click_count, :integer, :default => 0 + end +end diff --git a/source/db/schema.rb b/source/db/schema.rb index ceb914f..52bccba 100644 --- a/source/db/schema.rb +++ b/source/db/schema.rb @@ -11,13 +11,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180516234423) do +ActiveRecord::Schema.define(version: 20180517190422) do create_table "urls", force: true do |t| t.text "long_url" t.string "short_url" t.datetime "created_at" t.datetime "updated_at" + t.integer "click_count", default: 0 end end From 6b1c46e016a223b15d3f725bdfb318d32d91b482 Mon Sep 17 00:00:00 2001 From: Leslie Kornes Date: Thu, 17 May 2018 22:37:29 -0400 Subject: [PATCH 5/5] Fix a routing issue. Release 2 and 3. --- source/app/assets/stylesheets/custom.css.scss | 2 +- source/app/controllers/urls_controller.rb | 40 +++++++++---------- source/app/models/url.rb | 1 + source/app/views/urls/index.html.erb | 7 ++-- source/app/views/urls/new.html.erb | 2 +- source/app/views/urls/show.html.erb | 5 ++- source/config/routes.rb | 7 ++-- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/source/app/assets/stylesheets/custom.css.scss b/source/app/assets/stylesheets/custom.css.scss index b36f7e6..9cdae43 100644 --- a/source/app/assets/stylesheets/custom.css.scss +++ b/source/app/assets/stylesheets/custom.css.scss @@ -3,6 +3,6 @@ $navbar-default-bg: lightblue; @import "bootstrap-sprockets"; @import "bootstrap"; -.form-horizontal, .jumbotron { +.form-horizontal, .jumbotron, .table-bordered { margin-top: 75px; } diff --git a/source/app/controllers/urls_controller.rb b/source/app/controllers/urls_controller.rb index 9990a85..1a198f2 100644 --- a/source/app/controllers/urls_controller.rb +++ b/source/app/controllers/urls_controller.rb @@ -3,7 +3,7 @@ class UrlsController < ApplicationController def index if Url.all.size == 0 - flash[:danger] = "There aren't any yet. Why don't you start us off?" + flash.now[:danger] = "There aren't any yet. Why don't you start us off?" render 'home' else @urls = Url.all @@ -16,15 +16,7 @@ def new def create @url = Url.new(url_params) - #if check_url? - #flash.now[:danger] = "Check your URL. . ." - #render 'new' - #else - #@url.save - #flash.now[:success] = "Your URL is SHORT" - #redirect_to new_url_path(@url) - #end - if @url.save + if check_url? && @url.save redirect_to urls_path else flash.now[:danger] = "Something went wrong with your URL. . ." @@ -32,25 +24,31 @@ def create end end - def show + def short_url + @url = Url.find_by(short_url: params[:short_url]) @url.click_count += 1 @url.save - redirect_to "http://#{@url.long_url}" + redirect_to @url.long_url + end + + def show + end def home end private - def url_params - params.require(:url).permit(:long_url) - end + def url_params + params.require(:url).permit(:long_url) + end - def check_url? - @url.long_url.exclude?(".com") && @url.long_url.exclude?(".org") && @url.long_url.exclude?(".net") - end + def check_url? + url = URI.parse(@url.long_url) + url.is_a?(URI::HTTP) && !url.host.nil? + end - def set_url - @url = Url.find_by(short_url: params[:short_url]) - end + def set_url + @url = Url.find_by(params[:id]) + end end diff --git a/source/app/models/url.rb b/source/app/models/url.rb index a1103e8..ac2734f 100644 --- a/source/app/models/url.rb +++ b/source/app/models/url.rb @@ -1,4 +1,5 @@ class Url < ActiveRecord::Base + validates :long_url, presence: true before_create :trim_url private diff --git a/source/app/views/urls/index.html.erb b/source/app/views/urls/index.html.erb index ebe6ee8..3449ea9 100644 --- a/source/app/views/urls/index.html.erb +++ b/source/app/views/urls/index.html.erb @@ -5,14 +5,15 @@ Long Url Short Url - Clicks <% @urls.each do |url| %> - <%= url.long_url %> + <%= link_to url.long_url, url_path(url) %> <%= link_to url.short_url, short_url_path(url.short_url) %> - <%= url.click_count %> <% end %> +
+ [ <%= link_to "Home", root_path %> ] +
diff --git a/source/app/views/urls/new.html.erb b/source/app/views/urls/new.html.erb index 968ea8f..cc9a6e3 100644 --- a/source/app/views/urls/new.html.erb +++ b/source/app/views/urls/new.html.erb @@ -6,7 +6,7 @@ <%= f.label :long_url %>
- <%= f.text_field :long_url, class: "form-control", placeholder: "your-long-url.com", + <%= f.text_field :long_url, class: "form-control", placeholder: "https://your-long-url.com", autofocus: true %>
diff --git a/source/app/views/urls/show.html.erb b/source/app/views/urls/show.html.erb index 8619451..f8a4b45 100644 --- a/source/app/views/urls/show.html.erb +++ b/source/app/views/urls/show.html.erb @@ -7,9 +7,12 @@ <%= @url.long_url %> - <%= link_to "localhost:3000/urls/#{@url.short_url}", url_path(@url) %> + <%= link_to @url.short_url, short_url_path(@url.short_url) %> <%= @url.click_count %> +
+ [ <%= link_to "Home", root_path %> ] +
diff --git a/source/config/routes.rb b/source/config/routes.rb index 0819e28..dd1ba27 100644 --- a/source/config/routes.rb +++ b/source/config/routes.rb @@ -1,7 +1,8 @@ Rails.application.routes.draw do - root 'urls#home', only: [:index, :new, :create] - get '/url/:short_url', to: 'urls#show', as: "short_url" - + root 'urls#home' resources :urls + #get '/url/:short_url', to: 'urls#show', as: "short_url" + get '/url/:short_url', to: 'urls#short_url', as: "short_url" + end