Permalink
Browse files

setting up blog db

  • Loading branch information...
1 parent babc41c commit f312d6966180cdaa423a25a7ce693b32ad8de95e @voodoo committed Apr 27, 2012
View
3 Gemfile
@@ -5,7 +5,7 @@ gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'sqlite3'
+gem 'mysql2'
# Gems used only for assets and not required
@@ -27,6 +27,7 @@ gem 'unicorn'
# Deploy with Capistrano
gem 'capistrano'
+gem 'haml-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
11 Gemfile.lock
@@ -46,6 +46,12 @@ GEM
erubis (2.7.0)
execjs (1.3.1)
multi_json (~> 1.0)
+ haml (3.1.4)
+ haml-rails (0.3.4)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ haml (~> 3.0)
+ railties (~> 3.0)
highline (1.6.11)
hike (1.2.1)
i18n (0.6.0)
@@ -61,6 +67,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.3.2)
+ mysql2 (0.3.11)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
@@ -104,7 +111,6 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.6)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -125,9 +131,10 @@ PLATFORMS
DEPENDENCIES
capistrano
coffee-rails (~> 3.2.1)
+ haml-rails
jquery-rails
+ mysql2
rails (= 3.2.1)
sass-rails (~> 3.2.3)
- sqlite3
uglifier (>= 1.0.3)
unicorn
View
3 app/assets/javascripts/articles.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/
View
3 app/assets/stylesheets/articles.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the articles controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
56 app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
View
83 app/controllers/articles_controller.rb
@@ -0,0 +1,83 @@
+class ArticlesController < ApplicationController
+ # GET /articles
+ # GET /articles.json
+ def index
+ @articles = Article.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @articles }
+ end
+ end
+
+ # GET /articles/1
+ # GET /articles/1.json
+ def show
+ @article = Article.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @article }
+ end
+ end
+
+ # GET /articles/new
+ # GET /articles/new.json
+ def new
+ @article = Article.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @article }
+ end
+ end
+
+ # GET /articles/1/edit
+ def edit
+ @article = Article.find(params[:id])
+ end
+
+ # POST /articles
+ # POST /articles.json
+ def create
+ @article = Article.new(params[:article])
+
+ respond_to do |format|
+ if @article.save
+ format.html { redirect_to @article, notice: 'Article was successfully created.' }
+ format.json { render json: @article, status: :created, location: @article }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @article.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /articles/1
+ # PUT /articles/1.json
+ def update
+ @article = Article.find(params[:id])
+
+ respond_to do |format|
+ if @article.update_attributes(params[:article])
+ format.html { redirect_to @article, notice: 'Article was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @article.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /articles/1
+ # DELETE /articles/1.json
+ def destroy
+ @article = Article.find(params[:id])
+ @article.destroy
+
+ respond_to do |format|
+ format.html { redirect_to articles_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
2 app/helpers/articles_helper.rb
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
View
2 app/models/article.rb
@@ -0,0 +1,2 @@
+class Article < ActiveRecord::Base
+end
View
16 app/views/articles/_form.html.haml
@@ -0,0 +1,16 @@
+= form_for @article do |f|
+ -if @article.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@article.errors.count, "error")} prohibited this article from being saved:"
+ %ul
+ - @article.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :name
+ = f.text_field :name
+ .field
+ = f.label :content
+ = f.text_area :content
+ .actions
+ = f.submit 'Save'
View
7 app/views/articles/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing article
+
+= render 'form'
+
+= link_to 'Show', @article
+\|
+= link_to 'Back', articles_path
View
21 app/views/articles/index.html.haml
@@ -0,0 +1,21 @@
+%h1 Listing articles
+
+%table
+ %tr
+ %th Name
+ %th Content
+ %th
+ %th
+ %th
+
+ - @articles.each do |article|
+ %tr
+ %td= article.name
+ %td= article.content
+ %td= link_to 'Show', article
+ %td= link_to 'Edit', edit_article_path(article)
+ %td= link_to 'Destroy', article, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New Article', new_article_path
View
5 app/views/articles/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New article
+
+= render 'form'
+
+= link_to 'Back', articles_path
View
12 app/views/articles/show.html.haml
@@ -0,0 +1,12 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = @article.name
+%p
+ %b Content:
+ = @article.content
+
+= link_to 'Edit', edit_article_path(@article)
+\|
+= link_to 'Back', articles_path
View
2 config/routes.rb
@@ -1,4 +1,6 @@
Blog::Application.routes.draw do
+ resources :articles
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
10 db/migrate/20120427225133_create_articles.rb
@@ -0,0 +1,10 @@
+class CreateArticles < ActiveRecord::Migration
+ def change
+ create_table :articles do |t|
+ t.string :name
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
View
23 db/schema.rb
@@ -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 to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120427225133) do
+
+ create_table "articles", :force => true do |t|
+ t.string "name"
+ t.text "content"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
View
9 test/fixtures/articles.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ content: MyText
+
+two:
+ name: MyString
+ content: MyText
View
49 test/functional/articles_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ArticlesControllerTest < ActionController::TestCase
+ setup do
+ @article = articles(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:articles)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create article" do
+ assert_difference('Article.count') do
+ post :create, article: @article.attributes
+ end
+
+ assert_redirected_to article_path(assigns(:article))
+ end
+
+ test "should show article" do
+ get :show, id: @article
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @article
+ assert_response :success
+ end
+
+ test "should update article" do
+ put :update, id: @article, article: @article.attributes
+ assert_redirected_to article_path(assigns(:article))
+ end
+
+ test "should destroy article" do
+ assert_difference('Article.count', -1) do
+ delete :destroy, id: @article
+ end
+
+ assert_redirected_to articles_path
+ end
+end
View
7 test/unit/article_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ArticleTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/articles_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ArticlesHelperTest < ActionView::TestCase
+end

0 comments on commit f312d69

Please sign in to comment.