Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

setting up blog db

  • Loading branch information...
commit f312d6966180cdaa423a25a7ce693b32ad8de95e 1 parent babc41c
Paul Vudmaska authored April 27, 2012
3  Gemfile
@@ -5,7 +5,7 @@ gem 'rails', '3.2.1'
5 5
 # Bundle edge Rails instead:
6 6
 # gem 'rails', :git => 'git://github.com/rails/rails.git'
7 7
 
8  
-gem 'sqlite3'
  8
+gem 'mysql2'
9 9
 
10 10
 
11 11
 # Gems used only for assets and not required
@@ -27,6 +27,7 @@ gem 'unicorn'
27 27
 
28 28
 # Deploy with Capistrano
29 29
 gem 'capistrano'
  30
+gem 'haml-rails'
30 31
 
31 32
 # To use ActiveModel has_secure_password
32 33
 # gem 'bcrypt-ruby', '~> 3.0.0'
11  Gemfile.lock
@@ -46,6 +46,12 @@ GEM
46 46
     erubis (2.7.0)
47 47
     execjs (1.3.1)
48 48
       multi_json (~> 1.0)
  49
+    haml (3.1.4)
  50
+    haml-rails (0.3.4)
  51
+      actionpack (~> 3.0)
  52
+      activesupport (~> 3.0)
  53
+      haml (~> 3.0)
  54
+      railties (~> 3.0)
49 55
     highline (1.6.11)
50 56
     hike (1.2.1)
51 57
     i18n (0.6.0)
@@ -61,6 +67,7 @@ GEM
61 67
       treetop (~> 1.4.8)
62 68
     mime-types (1.18)
63 69
     multi_json (1.3.2)
  70
+    mysql2 (0.3.11)
64 71
     net-scp (1.0.4)
65 72
       net-ssh (>= 1.99.1)
66 73
     net-sftp (2.0.5)
@@ -104,7 +111,6 @@ GEM
104 111
       hike (~> 1.2)
105 112
       rack (~> 1.0)
106 113
       tilt (~> 1.1, != 1.3.0)
107  
-    sqlite3 (1.3.6)
108 114
     thor (0.14.6)
109 115
     tilt (1.3.3)
110 116
     treetop (1.4.10)
@@ -125,9 +131,10 @@ PLATFORMS
125 131
 DEPENDENCIES
126 132
   capistrano
127 133
   coffee-rails (~> 3.2.1)
  134
+  haml-rails
128 135
   jquery-rails
  136
+  mysql2
129 137
   rails (= 3.2.1)
130 138
   sass-rails (~> 3.2.3)
131  
-  sqlite3
132 139
   uglifier (>= 1.0.3)
133 140
   unicorn
3  app/assets/javascripts/articles.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/stylesheets/articles.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the articles controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
56  app/assets/stylesheets/scaffolds.css.scss
... ...
@@ -0,0 +1,56 @@
  1
+body {
  2
+  background-color: #fff;
  3
+  color: #333;
  4
+  font-family: verdana, arial, helvetica, sans-serif;
  5
+  font-size: 13px;
  6
+  line-height: 18px; }
  7
+
  8
+p, ol, ul, td {
  9
+  font-family: verdana, arial, helvetica, sans-serif;
  10
+  font-size: 13px;
  11
+  line-height: 18px; }
  12
+
  13
+pre {
  14
+  background-color: #eee;
  15
+  padding: 10px;
  16
+  font-size: 11px; }
  17
+
  18
+a {
  19
+  color: #000;
  20
+  &:visited {
  21
+    color: #666; }
  22
+  &:hover {
  23
+    color: #fff;
  24
+    background-color: #000; } }
  25
+
  26
+div {
  27
+  &.field, &.actions {
  28
+    margin-bottom: 10px; } }
  29
+
  30
+#notice {
  31
+  color: green; }
  32
+
  33
+.field_with_errors {
  34
+  padding: 2px;
  35
+  background-color: red;
  36
+  display: table; }
  37
+
  38
+#error_explanation {
  39
+  width: 450px;
  40
+  border: 2px solid red;
  41
+  padding: 7px;
  42
+  padding-bottom: 0;
  43
+  margin-bottom: 20px;
  44
+  background-color: #f0f0f0;
  45
+  h2 {
  46
+    text-align: left;
  47
+    font-weight: bold;
  48
+    padding: 5px 5px 5px 15px;
  49
+    font-size: 12px;
  50
+    margin: -7px;
  51
+    margin-bottom: 0px;
  52
+    background-color: #c00;
  53
+    color: #fff; }
  54
+  ul li {
  55
+    font-size: 12px;
  56
+    list-style: square; } }
83  app/controllers/articles_controller.rb
... ...
@@ -0,0 +1,83 @@
  1
+class ArticlesController < ApplicationController
  2
+  # GET /articles
  3
+  # GET /articles.json
  4
+  def index
  5
+    @articles = Article.all
  6
+
  7
+    respond_to do |format|
  8
+      format.html # index.html.erb
  9
+      format.json { render json: @articles }
  10
+    end
  11
+  end
  12
+
  13
+  # GET /articles/1
  14
+  # GET /articles/1.json
  15
+  def show
  16
+    @article = Article.find(params[:id])
  17
+
  18
+    respond_to do |format|
  19
+      format.html # show.html.erb
  20
+      format.json { render json: @article }
  21
+    end
  22
+  end
  23
+
  24
+  # GET /articles/new
  25
+  # GET /articles/new.json
  26
+  def new
  27
+    @article = Article.new
  28
+
  29
+    respond_to do |format|
  30
+      format.html # new.html.erb
  31
+      format.json { render json: @article }
  32
+    end
  33
+  end
  34
+
  35
+  # GET /articles/1/edit
  36
+  def edit
  37
+    @article = Article.find(params[:id])
  38
+  end
  39
+
  40
+  # POST /articles
  41
+  # POST /articles.json
  42
+  def create
  43
+    @article = Article.new(params[:article])
  44
+
  45
+    respond_to do |format|
  46
+      if @article.save
  47
+        format.html { redirect_to @article, notice: 'Article was successfully created.' }
  48
+        format.json { render json: @article, status: :created, location: @article }
  49
+      else
  50
+        format.html { render action: "new" }
  51
+        format.json { render json: @article.errors, status: :unprocessable_entity }
  52
+      end
  53
+    end
  54
+  end
  55
+
  56
+  # PUT /articles/1
  57
+  # PUT /articles/1.json
  58
+  def update
  59
+    @article = Article.find(params[:id])
  60
+
  61
+    respond_to do |format|
  62
+      if @article.update_attributes(params[:article])
  63
+        format.html { redirect_to @article, notice: 'Article was successfully updated.' }
  64
+        format.json { head :no_content }
  65
+      else
  66
+        format.html { render action: "edit" }
  67
+        format.json { render json: @article.errors, status: :unprocessable_entity }
  68
+      end
  69
+    end
  70
+  end
  71
+
  72
+  # DELETE /articles/1
  73
+  # DELETE /articles/1.json
  74
+  def destroy
  75
+    @article = Article.find(params[:id])
  76
+    @article.destroy
  77
+
  78
+    respond_to do |format|
  79
+      format.html { redirect_to articles_url }
  80
+      format.json { head :no_content }
  81
+    end
  82
+  end
  83
+end
2  app/helpers/articles_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module ArticlesHelper
  2
+end
2  app/models/article.rb
... ...
@@ -0,0 +1,2 @@
  1
+class Article < ActiveRecord::Base
  2
+end
16  app/views/articles/_form.html.haml
... ...
@@ -0,0 +1,16 @@
  1
+= form_for @article do |f|
  2
+  -if @article.errors.any?
  3
+    #error_explanation
  4
+      %h2= "#{pluralize(@article.errors.count, "error")} prohibited this article from being saved:"
  5
+      %ul
  6
+        - @article.errors.full_messages.each do |msg|
  7
+          %li= msg
  8
+
  9
+  .field
  10
+    = f.label :name
  11
+    = f.text_field :name
  12
+  .field
  13
+    = f.label :content
  14
+    = f.text_area :content
  15
+  .actions
  16
+    = f.submit 'Save'
7  app/views/articles/edit.html.haml
... ...
@@ -0,0 +1,7 @@
  1
+%h1 Editing article
  2
+
  3
+= render 'form'
  4
+
  5
+= link_to 'Show', @article
  6
+\|
  7
+= link_to 'Back', articles_path
21  app/views/articles/index.html.haml
... ...
@@ -0,0 +1,21 @@
  1
+%h1 Listing articles
  2
+
  3
+%table
  4
+  %tr
  5
+    %th Name
  6
+    %th Content
  7
+    %th
  8
+    %th
  9
+    %th
  10
+
  11
+  - @articles.each do |article|
  12
+    %tr
  13
+      %td= article.name
  14
+      %td= article.content
  15
+      %td= link_to 'Show', article
  16
+      %td= link_to 'Edit', edit_article_path(article)
  17
+      %td= link_to 'Destroy', article, :confirm => 'Are you sure?', :method => :delete
  18
+
  19
+%br
  20
+
  21
+= link_to 'New Article', new_article_path
5  app/views/articles/new.html.haml
... ...
@@ -0,0 +1,5 @@
  1
+%h1 New article
  2
+
  3
+= render 'form'
  4
+
  5
+= link_to 'Back', articles_path
12  app/views/articles/show.html.haml
... ...
@@ -0,0 +1,12 @@
  1
+%p#notice= notice
  2
+
  3
+%p
  4
+  %b Name:
  5
+  = @article.name
  6
+%p
  7
+  %b Content:
  8
+  = @article.content
  9
+
  10
+= link_to 'Edit', edit_article_path(@article)
  11
+\|
  12
+= link_to 'Back', articles_path
2  config/routes.rb
... ...
@@ -1,4 +1,6 @@
1 1
 Blog::Application.routes.draw do
  2
+  resources :articles
  3
+
2 4
   # The priority is based upon order of creation:
3 5
   # first created -> highest priority.
4 6
 
10  db/migrate/20120427225133_create_articles.rb
... ...
@@ -0,0 +1,10 @@
  1
+class CreateArticles < ActiveRecord::Migration
  2
+  def change
  3
+    create_table :articles do |t|
  4
+      t.string :name
  5
+      t.text :content
  6
+
  7
+      t.timestamps
  8
+    end
  9
+  end
  10
+end
23  db/schema.rb
... ...
@@ -0,0 +1,23 @@
  1
+# encoding: UTF-8
  2
+# This file is auto-generated from the current state of the database. Instead
  3
+# of editing this file, please use the migrations feature of Active Record to
  4
+# incrementally modify your database, and then regenerate this schema definition.
  5
+#
  6
+# Note that this schema.rb definition is the authoritative source for your
  7
+# database schema. If you need to create the application database on another
  8
+# system, you should be using db:schema:load, not running all the migrations
  9
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
  10
+# you'll amass, the slower it'll run and the greater likelihood for issues).
  11
+#
  12
+# It's strongly recommended to check this file into your version control system.
  13
+
  14
+ActiveRecord::Schema.define(:version => 20120427225133) do
  15
+
  16
+  create_table "articles", :force => true do |t|
  17
+    t.string   "name"
  18
+    t.text     "content"
  19
+    t.datetime "created_at", :null => false
  20
+    t.datetime "updated_at", :null => false
  21
+  end
  22
+
  23
+end
9  test/fixtures/articles.yml
... ...
@@ -0,0 +1,9 @@
  1
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
  2
+
  3
+one:
  4
+  name: MyString
  5
+  content: MyText
  6
+
  7
+two:
  8
+  name: MyString
  9
+  content: MyText
49  test/functional/articles_controller_test.rb
... ...
@@ -0,0 +1,49 @@
  1
+require 'test_helper'
  2
+
  3
+class ArticlesControllerTest < ActionController::TestCase
  4
+  setup do
  5
+    @article = articles(:one)
  6
+  end
  7
+
  8
+  test "should get index" do
  9
+    get :index
  10
+    assert_response :success
  11
+    assert_not_nil assigns(:articles)
  12
+  end
  13
+
  14
+  test "should get new" do
  15
+    get :new
  16
+    assert_response :success
  17
+  end
  18
+
  19
+  test "should create article" do
  20
+    assert_difference('Article.count') do
  21
+      post :create, article: @article.attributes
  22
+    end
  23
+
  24
+    assert_redirected_to article_path(assigns(:article))
  25
+  end
  26
+
  27
+  test "should show article" do
  28
+    get :show, id: @article
  29
+    assert_response :success
  30
+  end
  31
+
  32
+  test "should get edit" do
  33
+    get :edit, id: @article
  34
+    assert_response :success
  35
+  end
  36
+
  37
+  test "should update article" do
  38
+    put :update, id: @article, article: @article.attributes
  39
+    assert_redirected_to article_path(assigns(:article))
  40
+  end
  41
+
  42
+  test "should destroy article" do
  43
+    assert_difference('Article.count', -1) do
  44
+      delete :destroy, id: @article
  45
+    end
  46
+
  47
+    assert_redirected_to articles_path
  48
+  end
  49
+end
7  test/unit/article_test.rb
... ...
@@ -0,0 +1,7 @@
  1
+require 'test_helper'
  2
+
  3
+class ArticleTest < ActiveSupport::TestCase
  4
+  # test "the truth" do
  5
+  #   assert true
  6
+  # end
  7
+end
4  test/unit/helpers/articles_helper_test.rb
... ...
@@ -0,0 +1,4 @@
  1
+require 'test_helper'
  2
+
  3
+class ArticlesHelperTest < ActionView::TestCase
  4
+end

0 notes on commit f312d69

Please sign in to comment.
Something went wrong with that request. Please try again.