diff --git a/app/assets/javascripts/home.js.coffee b/app/assets/javascripts/home.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/home.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/links.js.coffee b/app/assets/javascripts/links.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/links.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/home.css.scss b/app/assets/stylesheets/home.css.scss new file mode 100644 index 0000000..f0ddc68 --- /dev/null +++ b/app/assets/stylesheets/home.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/links.css.scss b/app/assets/stylesheets/links.css.scss new file mode 100644 index 0000000..220eb70 --- /dev/null +++ b/app/assets/stylesheets/links.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Links controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..95f2992 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,4 @@ +class HomeController < ApplicationController + def index + end +end diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb new file mode 100644 index 0000000..c0b2a8b --- /dev/null +++ b/app/controllers/links_controller.rb @@ -0,0 +1,27 @@ +class LinksController < ApplicationController + def index + @links = Link.released + + respond_to do |format| + format.html + format.json { render :json => @links } + end + end + + def new + end + + def create + end + + def show + @link = Link.goto(params[:id]) + + #update link count + + respond_to do |format| + format.html { redirect_to @link.url } + format.json { render :json => @link } + end + end +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/helpers/links_helper.rb b/app/helpers/links_helper.rb new file mode 100644 index 0000000..f6bc988 --- /dev/null +++ b/app/helpers/links_helper.rb @@ -0,0 +1,2 @@ +module LinksHelper +end diff --git a/app/models/link.rb b/app/models/link.rb new file mode 100644 index 0000000..2efee43 --- /dev/null +++ b/app/models/link.rb @@ -0,0 +1,21 @@ +class Link < ActiveRecord::Base + attr_accessible :description, :release, :url + validates :url, :presence => true, :url => true + validates :description, :presence => true + + def released + Link.where("DATE(release) <= DATE(?)", Time.now).order("release DESC") + end + + def goto(id = nil) + return false if nil + + Link.transaction do + link = Link.find(id) + link.visits += 1 + link.save + end + + return link + end +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..2085730 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,2 @@ +
Find me in app/views/home/index.html.erb
diff --git a/app/views/links/0 b/app/views/links/0 new file mode 100644 index 0000000..54b4b7b --- /dev/null +++ b/app/views/links/0 @@ -0,0 +1,2 @@ +[1m[37m invoke[0m active_record +[1m[32m create[0m db/migrate/20120503045327_change_column.rb diff --git a/app/views/links/index.html.erb b/app/views/links/index.html.erb new file mode 100644 index 0000000..7b1c5e4 --- /dev/null +++ b/app/views/links/index.html.erb @@ -0,0 +1,2 @@ +Find me in app/views/links/index.html.erb
diff --git a/config/routes.rb b/config/routes.rb index b7b0517..1db8f54 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ WwwWhoisandrewCom::Application.routes.draw do + resources :links + + root :to => "home#index" + # The priority is based upon order of creation: # first created -> highest priority. diff --git a/db/migrate/20120503030309_create_links.rb b/db/migrate/20120503030309_create_links.rb new file mode 100644 index 0000000..19de930 --- /dev/null +++ b/db/migrate/20120503030309_create_links.rb @@ -0,0 +1,11 @@ +class CreateLinks < ActiveRecord::Migration + def change + create_table :links do |t| + t.string :url + t.text :description + t.datetime :release + + t.timestamps + end + end +end diff --git a/db/migrate/20120503043353_add_visits_to_link.rb b/db/migrate/20120503043353_add_visits_to_link.rb new file mode 100644 index 0000000..c6a45e3 --- /dev/null +++ b/db/migrate/20120503043353_add_visits_to_link.rb @@ -0,0 +1,5 @@ +class AddVisitsToLink < ActiveRecord::Migration + def change + add_column :links, :visits, :integer + end +end diff --git a/db/migrate/20120503051402_set_default_visits.rb b/db/migrate/20120503051402_set_default_visits.rb new file mode 100644 index 0000000..62bee2b --- /dev/null +++ b/db/migrate/20120503051402_set_default_visits.rb @@ -0,0 +1,9 @@ +class SetDefaultVisits < ActiveRecord::Migration + def up + change_column :links, :visits, :integer, :null => false, :default => 0 + end + + def down + raise ActiveRecord::IrreversibleMigration, "Can't remove the default" + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..e2ffe1d --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,25 @@ +# 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 to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20120503051402) do + + create_table "links", :force => true do |t| + t.string "url" + t.text "description" + t.datetime "release" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "visits", :default => 0, :null => false + end + +end diff --git a/test/fixtures/links.yml b/test/fixtures/links.yml new file mode 100644 index 0000000..6116258 --- /dev/null +++ b/test/fixtures/links.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + url: MyString + description: MyText + release: 2012-05-02 23:03:09 + +two: + url: MyString + description: MyText + release: 2012-05-02 23:03:09 diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb new file mode 100644 index 0000000..0d9bb47 --- /dev/null +++ b/test/functional/home_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class HomeControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + +end diff --git a/test/functional/links_controller_test.rb b/test/functional/links_controller_test.rb new file mode 100644 index 0000000..37056f6 --- /dev/null +++ b/test/functional/links_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class LinksControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + +end diff --git a/test/unit/helpers/home_helper_test.rb b/test/unit/helpers/home_helper_test.rb new file mode 100644 index 0000000..4740a18 --- /dev/null +++ b/test/unit/helpers/home_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class HomeHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/links_helper_test.rb b/test/unit/helpers/links_helper_test.rb new file mode 100644 index 0000000..3ff1dea --- /dev/null +++ b/test/unit/helpers/links_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class LinksHelperTest < ActionView::TestCase +end diff --git a/test/unit/link_test.rb b/test/unit/link_test.rb new file mode 100644 index 0000000..944bfce --- /dev/null +++ b/test/unit/link_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class LinkTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end