diff --git a/app/assets/javascripts/blogs.js.coffee b/app/assets/javascripts/blogs.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/blogs.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/blogs.css.scss b/app/assets/stylesheets/blogs.css.scss new file mode 100644 index 0000000..59c4c25 --- /dev/null +++ b/app/assets/stylesheets/blogs.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Blogs 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/blogs_controller.rb b/app/controllers/blogs_controller.rb new file mode 100644 index 0000000..806b175 --- /dev/null +++ b/app/controllers/blogs_controller.rb @@ -0,0 +1,19 @@ +class BlogsController < ApplicationController + def index + @blogs = Blog.released + + respond_to do |format| + format.html + format.json { render :json => @blogs } + end + end + + def show + @blog = Blog.get(params[:id]) + + respond_to do |format| + format.html + format.json { render :json => @blog } + end + +end diff --git a/app/helpers/blogs_helper.rb b/app/helpers/blogs_helper.rb new file mode 100644 index 0000000..cc0dbd2 --- /dev/null +++ b/app/helpers/blogs_helper.rb @@ -0,0 +1,2 @@ +module BlogsHelper +end diff --git a/app/models/blog.rb b/app/models/blog.rb new file mode 100644 index 0000000..db77900 --- /dev/null +++ b/app/models/blog.rb @@ -0,0 +1,9 @@ +class Blog < ActiveRecord::Base + attr_accessible :title, :body, :release + validates :title, :presence => true, :length { minimum: 3 } + validates :body, :presence => true + + def self.released + Blog.where("DATE(release) <= DATE(?)", Time.now).order("release DESC") + end +end diff --git a/config/routes.rb b/config/routes.rb index 1db8f54..090753c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ WwwWhoisandrewCom::Application.routes.draw do resources :links + resources :blogs root :to => "home#index" diff --git a/db/migrate/20120505032057_create_blogs.rb b/db/migrate/20120505032057_create_blogs.rb new file mode 100644 index 0000000..c8e59bc --- /dev/null +++ b/db/migrate/20120505032057_create_blogs.rb @@ -0,0 +1,11 @@ +class CreateBlogs < ActiveRecord::Migration + def change + create_table :blogs do |t| + t.string :title + t.text :body + t.datetime :release + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e2ffe1d..fbca997 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,15 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120503051402) do +ActiveRecord::Schema.define(:version => 20120505032057) do + + create_table "blogs", :force => true do |t| + t.string "title" + t.text "body" + t.datetime "release" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end create_table "links", :force => true do |t| t.string "url" diff --git a/test/fixtures/blogs.yml b/test/fixtures/blogs.yml new file mode 100644 index 0000000..c63aac0 --- /dev/null +++ b/test/fixtures/blogs.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/functional/blogs_controller_test.rb b/test/functional/blogs_controller_test.rb new file mode 100644 index 0000000..be92e9c --- /dev/null +++ b/test/functional/blogs_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BlogsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb new file mode 100644 index 0000000..5038377 --- /dev/null +++ b/test/unit/blog_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BlogTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/blogs_helper_test.rb b/test/unit/helpers/blogs_helper_test.rb new file mode 100644 index 0000000..5508886 --- /dev/null +++ b/test/unit/helpers/blogs_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class BlogsHelperTest < ActionView::TestCase +end