-
Notifications
You must be signed in to change notification settings - Fork 40
90% done with step 0 #27
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
Open
ewarman
wants to merge
1
commit into
paircolumbus:master
Choose a base branch
from
ewarman:ew-solution
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| class UrlsController < ApplicationController | ||
| def index | ||
| @urls = Url.all | ||
| end | ||
|
|
||
| def new | ||
| @url = Url.new | ||
| end | ||
|
|
||
| def show | ||
| @url = Url.find(params[:id]) | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class Url < ActiveRecord::Base | ||
|
|
||
| before_save :shorten_url | ||
| validates_uniqueness_of :unique_key | ||
|
|
||
| private | ||
| #generate 6 digit unique identifier | ||
| def shorten_url(record) | ||
| if self.unique_key.nil? | ||
| self.unique_key = 6.times.map { [*'0'..'9', *'A'..'Z'].sample }.join | ||
| end | ||
| end | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <h1>All Urls</h1> | ||
| <table> | ||
| <thead> | ||
| </thead> | ||
| <tbody> | ||
| <% @urls.each do |url| %> | ||
| <tr> | ||
| <td><% link_to root_url+url.unique_key, url.unique_key %></td> | ||
| <td><% url.address %></td> | ||
| </tr> | ||
| <% end %> | ||
| <%if @urls.empty? %> | ||
| <p> No urls to show </p> | ||
| <% end %> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| <br> | ||
| <%= link_to "New Url",new_url_path %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <h1>Create a new link</h1> | ||
| <%= form_for @url do |f| %> | ||
| <p> | ||
| <%= f.label :address %><br> | ||
| <%= f.text_field :address %> | ||
| </p> | ||
| <p> | ||
| <%= f.submit %> | ||
| </p> | ||
| <% end %> | ||
|
|
||
| <%= link_to 'Back', urls_path %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| resources :urls | ||
| root 'urls#index' | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class CreateUrls < ActiveRecord::Migration | ||
| def change | ||
| create_table :urls do |t| | ||
| t.string :address | ||
| t.string :unique_key | ||
| t.timestamps | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: 20170120134736) do | ||
|
|
||
| create_table "urls", force: true do |t| | ||
| t.string "address" | ||
| t.string "unique_key" | ||
| t.datetime "created_at" | ||
| t.datetime "updated_at" | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Url, type: :model do | ||
| pending "add some examples to (or delete) #{__FILE__}" | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This array of characters you're calling
sampleon can be extracted to a constant. That way ruby doesn't have to reconstruct it 6 times for every call to this method.