Setup blog controller and model.
This commit is contained in:
parent
87232d64ee
commit
08dff24760
12 changed files with 86 additions and 1 deletions
3
app/assets/javascripts/blogs.js.coffee
Normal file
3
app/assets/javascripts/blogs.js.coffee
Normal file
|
@ -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/
|
3
app/assets/stylesheets/blogs.css.scss
Normal file
3
app/assets/stylesheets/blogs.css.scss
Normal file
|
@ -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/
|
19
app/controllers/blogs_controller.rb
Normal file
19
app/controllers/blogs_controller.rb
Normal file
|
@ -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
|
2
app/helpers/blogs_helper.rb
Normal file
2
app/helpers/blogs_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module BlogsHelper
|
||||
end
|
9
app/models/blog.rb
Normal file
9
app/models/blog.rb
Normal file
|
@ -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
|
|
@ -1,5 +1,6 @@
|
|||
WwwWhoisandrewCom::Application.routes.draw do
|
||||
resources :links
|
||||
resources :blogs
|
||||
|
||||
root :to => "home#index"
|
||||
|
||||
|
|
11
db/migrate/20120505032057_create_blogs.rb
Normal file
11
db/migrate/20120505032057_create_blogs.rb
Normal file
|
@ -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
|
10
db/schema.rb
10
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"
|
||||
|
|
11
test/fixtures/blogs.yml
vendored
Normal file
11
test/fixtures/blogs.yml
vendored
Normal file
|
@ -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
|
7
test/functional/blogs_controller_test.rb
Normal file
7
test/functional/blogs_controller_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class BlogsControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
7
test/unit/blog_test.rb
Normal file
7
test/unit/blog_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class BlogTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
4
test/unit/helpers/blogs_helper_test.rb
Normal file
4
test/unit/helpers/blogs_helper_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class BlogsHelperTest < ActionView::TestCase
|
||||
end
|
Loading…
Reference in a new issue