forked from aprendegit/fork
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ec8926
commit 3dce05d
Showing
25 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the Posts controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class HomeController < ApplicationController | ||
def index | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class PostsController < ApplicationController | ||
# GET /posts | ||
# GET /posts.json | ||
def index | ||
@posts = Post.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @posts } | ||
end | ||
end | ||
|
||
# GET /posts/1 | ||
# GET /posts/1.json | ||
def show | ||
@post = Post.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @post } | ||
end | ||
end | ||
|
||
# GET /posts/new | ||
# GET /posts/new.json | ||
def new | ||
@post = Post.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render json: @post } | ||
end | ||
end | ||
|
||
# GET /posts/1/edit | ||
def edit | ||
@post = Post.find(params[:id]) | ||
end | ||
|
||
# POST /posts | ||
# POST /posts.json | ||
def create | ||
@post = Post.new(params[:post]) | ||
|
||
respond_to do |format| | ||
if @post.save | ||
format.html { redirect_to @post, notice: 'Post was successfully created.' } | ||
format.json { render json: @post, status: :created, location: @post } | ||
else | ||
format.html { render action: "new" } | ||
format.json { render json: @post.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /posts/1 | ||
# PUT /posts/1.json | ||
def update | ||
@post = Post.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @post.update_attributes(params[:post]) | ||
format.html { redirect_to @post, notice: 'Post was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @post.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /posts/1 | ||
# DELETE /posts/1.json | ||
def destroy | ||
@post = Post.find(params[:id]) | ||
@post.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to posts_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module HomeHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PostsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Post < ActiveRecord::Base | ||
attr_accessible :content, :name, :title | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Home#index</h1> | ||
<p>Find me in app/views/home/index.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<%= form_for(@post) do |f| %> | ||
<% if @post.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> | ||
|
||
<ul> | ||
<% @post.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :name %><br /> | ||
<%= f.text_field :name %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :title %><br /> | ||
<%= f.text_field :title %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :content %><br /> | ||
<%= f.text_area :content %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing post</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @post %> | | ||
<%= link_to 'Back', posts_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<h1>Listing posts</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Name</th> | ||
<th>Title</th> | ||
<th>Content</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @posts.each do |post| %> | ||
<tr> | ||
<td><%= post.name %></td> | ||
<td><%= post.title %></td> | ||
<td><%= post.content %></td> | ||
<td><%= link_to 'Show', post %></td> | ||
<td><%= link_to 'Edit', edit_post_path(post) %></td> | ||
<td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Post', new_post_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New post</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', posts_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<p> | ||
<b>Name:</b> | ||
<%= @post.name %> | ||
</p> | ||
|
||
<p> | ||
<b>Title:</b> | ||
<%= @post.title %> | ||
</p> | ||
|
||
<p> | ||
<b>Content:</b> | ||
<%= @post.content %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_post_path(@post) %> | | ||
<%= link_to 'Back', posts_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreatePosts < ActiveRecord::Migration | ||
def change | ||
create_table :posts do |t| | ||
t.string :name | ||
t.string :title | ||
t.text :content | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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 => 20130128100114) do | ||
|
||
create_table "posts", :force => true do |t| | ||
t.string "name" | ||
t.string "title" | ||
t.text "content" | ||
t.datetime "created_at", :null => false | ||
t.datetime "updated_at", :null => false | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | ||
|
||
one: | ||
name: MyString | ||
title: MyString | ||
content: MyText | ||
|
||
two: | ||
name: MyString | ||
title: MyString | ||
content: MyText |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'test_helper' | ||
|
||
class HomeControllerTest < ActionController::TestCase | ||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'test_helper' | ||
|
||
class PostsControllerTest < ActionController::TestCase | ||
setup do | ||
@post = posts(:one) | ||
end | ||
|
||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
assert_not_nil assigns(:posts) | ||
end | ||
|
||
test "should get new" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "should create post" do | ||
assert_difference('Post.count') do | ||
post :create, post: { content: @post.content, name: @post.name, title: @post.title } | ||
end | ||
|
||
assert_redirected_to post_path(assigns(:post)) | ||
end | ||
|
||
test "should show post" do | ||
get :show, id: @post | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get :edit, id: @post | ||
assert_response :success | ||
end | ||
|
||
test "should update post" do | ||
put :update, id: @post, post: { content: @post.content, name: @post.name, title: @post.title } | ||
assert_redirected_to post_path(assigns(:post)) | ||
end | ||
|
||
test "should destroy post" do | ||
assert_difference('Post.count', -1) do | ||
delete :destroy, id: @post | ||
end | ||
|
||
assert_redirected_to posts_path | ||
end | ||
end |
Oops, something went wrong.