-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from xiongbo/master
finished 409
- Loading branch information
Showing
81 changed files
with
1,091 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,15 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
# | ||
# If you find yourself ignoring temporary files generated by your text editor | ||
# or operating system, you probably want to add a global ignore instead: | ||
# git config --global core.excludesfile ~/.gitignore_global | ||
|
||
# Ignore bundler config | ||
/.bundle | ||
|
||
# Ignore the default SQLite database. | ||
/db/*.sqlite3 | ||
|
||
# Ignore all logfiles and tempfiles. | ||
/log/*.log | ||
/tmp |
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,38 @@ | ||
source 'http://ruby.taobao.org' | ||
|
||
gem 'rails', '3.2.13' | ||
|
||
# Bundle edge Rails instead: | ||
# gem 'rails', :git => 'git://github.com/rails/rails.git' | ||
|
||
gem 'sqlite3' | ||
|
||
|
||
# Gems used only for assets and not required | ||
# in production environments by default. | ||
group :assets do | ||
gem 'sass-rails', '~> 3.2.3' | ||
gem 'coffee-rails', '~> 3.2.1' | ||
|
||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes | ||
# gem 'therubyracer', :platforms => :ruby | ||
|
||
gem 'uglifier', '>= 1.0.3' | ||
end | ||
|
||
gem 'jquery-rails' | ||
gem 'active_model_serializers' | ||
|
||
# To use ActiveModel has_secure_password | ||
# gem 'bcrypt-ruby', '~> 3.0.0' | ||
|
||
# To use Jbuilder templates for JSON | ||
# gem 'jbuilder' | ||
# Use unicorn as the app server | ||
# gem 'unicorn' | ||
|
||
# Deploy with Capistrano | ||
# gem 'capistrano' | ||
|
||
# To use debugger | ||
# gem 'debugger' |
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,113 @@ | ||
GEM | ||
remote: http://ruby.taobao.org/ | ||
specs: | ||
actionmailer (3.2.13) | ||
actionpack (= 3.2.13) | ||
mail (~> 2.5.3) | ||
actionpack (3.2.13) | ||
activemodel (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
builder (~> 3.0.0) | ||
erubis (~> 2.7.0) | ||
journey (~> 1.0.4) | ||
rack (~> 1.4.5) | ||
rack-cache (~> 1.2) | ||
rack-test (~> 0.6.1) | ||
sprockets (~> 2.2.1) | ||
active_model_serializers (0.8.1) | ||
activemodel (>= 3.0) | ||
activemodel (3.2.13) | ||
activesupport (= 3.2.13) | ||
builder (~> 3.0.0) | ||
activerecord (3.2.13) | ||
activemodel (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
arel (~> 3.0.2) | ||
tzinfo (~> 0.3.29) | ||
activeresource (3.2.13) | ||
activemodel (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
activesupport (3.2.13) | ||
i18n (= 0.6.1) | ||
multi_json (~> 1.0) | ||
arel (3.0.2) | ||
builder (3.0.4) | ||
coffee-rails (3.2.2) | ||
coffee-script (>= 2.2.0) | ||
railties (~> 3.2.0) | ||
coffee-script (2.2.0) | ||
coffee-script-source | ||
execjs | ||
coffee-script-source (1.6.3) | ||
erubis (2.7.0) | ||
execjs (2.0.0) | ||
hike (1.2.3) | ||
i18n (0.6.1) | ||
journey (1.0.4) | ||
jquery-rails (3.0.4) | ||
railties (>= 3.0, < 5.0) | ||
thor (>= 0.14, < 2.0) | ||
json (1.8.0) | ||
mail (2.5.4) | ||
mime-types (~> 1.16) | ||
treetop (~> 1.4.8) | ||
mime-types (1.24) | ||
multi_json (1.7.9) | ||
polyglot (0.3.3) | ||
rack (1.4.5) | ||
rack-cache (1.2) | ||
rack (>= 0.4) | ||
rack-ssl (1.3.3) | ||
rack | ||
rack-test (0.6.2) | ||
rack (>= 1.0) | ||
rails (3.2.13) | ||
actionmailer (= 3.2.13) | ||
actionpack (= 3.2.13) | ||
activerecord (= 3.2.13) | ||
activeresource (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
bundler (~> 1.0) | ||
railties (= 3.2.13) | ||
railties (3.2.13) | ||
actionpack (= 3.2.13) | ||
activesupport (= 3.2.13) | ||
rack-ssl (~> 1.3.2) | ||
rake (>= 0.8.7) | ||
rdoc (~> 3.4) | ||
thor (>= 0.14.6, < 2.0) | ||
rake (10.1.0) | ||
rdoc (3.12.2) | ||
json (~> 1.4) | ||
sass (3.2.10) | ||
sass-rails (3.2.6) | ||
railties (~> 3.2.0) | ||
sass (>= 3.1.10) | ||
tilt (~> 1.3) | ||
sprockets (2.2.2) | ||
hike (~> 1.2) | ||
multi_json (~> 1.0) | ||
rack (~> 1.0) | ||
tilt (~> 1.1, != 1.3.0) | ||
sqlite3 (1.3.8) | ||
thor (0.18.1) | ||
tilt (1.4.1) | ||
treetop (1.4.15) | ||
polyglot | ||
polyglot (>= 0.3.1) | ||
tzinfo (0.3.37) | ||
uglifier (2.2.0) | ||
execjs (>= 0.3.0) | ||
multi_json (~> 1.0, >= 1.0.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
active_model_serializers | ||
coffee-rails (~> 3.2.1) | ||
jquery-rails | ||
rails (= 3.2.13) | ||
sass-rails (~> 3.2.3) | ||
sqlite3 | ||
uglifier (>= 1.0.3) |
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 @@ | ||
# RailsCasts Example Application | ||
|
||
Run these commands to try it out. | ||
|
||
``` | ||
bundle | ||
rake db:setup | ||
rails s | ||
``` | ||
|
||
Requires Ruby 1.9.2 or later to run. |
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,7 @@ | ||
#!/usr/bin/env rake | ||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require File.expand_path('../config/application', __FILE__) | ||
|
||
Blog::Application.load_tasks |
15 changes: 15 additions & 0 deletions
15
xiongbo/409-active-model-serializers/blog/app/assets/javascripts/application.js
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,15 @@ | ||
// This is a manifest file that'll be compiled into application.js, which will include all the files | ||
// listed below. | ||
// | ||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, | ||
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. | ||
// | ||
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | ||
// the compiled file. | ||
// | ||
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD | ||
// GO AFTER THE REQUIRES BELOW. | ||
// | ||
//= require jquery | ||
//= require jquery_ujs | ||
//= require_tree . |
3 changes: 3 additions & 0 deletions
3
xiongbo/409-active-model-serializers/blog/app/assets/javascripts/articles.js.coffee
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/ |
3 changes: 3 additions & 0 deletions
3
xiongbo/409-active-model-serializers/blog/app/assets/javascripts/comments.js.coffee
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/ |
13 changes: 13 additions & 0 deletions
13
xiongbo/409-active-model-serializers/blog/app/assets/stylesheets/application.css
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,13 @@ | ||
/* | ||
* This is a manifest file that'll be compiled into application.css, which will include all the files | ||
* listed below. | ||
* | ||
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, | ||
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. | ||
* | ||
* You're free to add application-wide styles to this file and they'll appear at the top of the | ||
* compiled file, but it's generally better to create a new file per style scope. | ||
* | ||
*= require_self | ||
*= require_tree . | ||
*/ |
38 changes: 38 additions & 0 deletions
38
xiongbo/409-active-model-serializers/blog/app/assets/stylesheets/articles.css.scss
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,38 @@ | ||
#articles h2 { | ||
font-size: 16px; | ||
margin-bottom: 2px; | ||
margin-top: 20px; | ||
} | ||
|
||
#articles h2 .comments { | ||
font-size: 12px; | ||
font-weight: normal; | ||
} | ||
|
||
#articles .info { | ||
font-style: italic; | ||
color: #333; | ||
margin-bottom: 8px; | ||
font-size: 12px; | ||
} | ||
|
||
#comments { | ||
font-size: 12px; | ||
background-color: #EEE; | ||
padding: 0 20px; | ||
width: 325px; | ||
border: solid 1px #777; | ||
} | ||
|
||
.comment { | ||
border-bottom: solid 1px #999; | ||
margin: 15px 0; | ||
} | ||
|
||
.comment:last-child { | ||
border-bottom: none; | ||
} | ||
|
||
.comment .author_name { | ||
font-weight: bold; | ||
} |
3 changes: 3 additions & 0 deletions
3
xiongbo/409-active-model-serializers/blog/app/assets/stylesheets/comments.css.scss
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 comments controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
64 changes: 64 additions & 0 deletions
64
xiongbo/409-active-model-serializers/blog/app/assets/stylesheets/layout.css.scss
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,64 @@ | ||
html, body { | ||
background-color: #4B7399; | ||
font-family: Verdana, Helvetica, Arial; | ||
font-size: 14px; | ||
} | ||
|
||
a { | ||
color: #0000FF; | ||
img { border: none; } | ||
} | ||
|
||
.clear { | ||
clear: both; | ||
height: 0; | ||
overflow: hidden; | ||
} | ||
|
||
#container { | ||
width: 80%; | ||
margin: 0 auto; | ||
background-color: #FFF; | ||
padding: 20px 40px; | ||
border: solid 1px black; | ||
margin-top: 20px; | ||
} | ||
|
||
#flash_notice { | ||
color: #00B205; | ||
} | ||
|
||
#flash_alert { | ||
color: #D00; | ||
} | ||
|
||
.error_messages, #error_explanation { | ||
width: 400px; | ||
border: 2px solid #CF0000; | ||
padding: 0px; | ||
padding-bottom: 12px; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
font-size: 12px; | ||
|
||
h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 10px; | ||
font-size: 12px; | ||
margin: 0; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
p { margin: 8px 10px; } | ||
ul { margin-bottom: 0; } | ||
} | ||
|
||
.field_with_errors { | ||
display: inline; | ||
} | ||
|
||
form .field, form .actions { | ||
margin: 12px 0; | ||
} |
12 changes: 12 additions & 0 deletions
12
xiongbo/409-active-model-serializers/blog/app/controllers/application_controller.rb
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,12 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
|
||
serialization_scope :view_context | ||
|
||
private | ||
|
||
def current_user | ||
OpenStruct.new(admin?: false) | ||
end | ||
helper_method :current_user | ||
end |
18 changes: 18 additions & 0 deletions
18
xiongbo/409-active-model-serializers/blog/app/controllers/articles_controller.rb
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,18 @@ | ||
class ArticlesController < ApplicationController | ||
respond_to :html, :json | ||
def index | ||
@articles = Article.all | ||
end | ||
|
||
def show | ||
@article = Article.find(params[:id]) | ||
respond_to do |format| | ||
format.html { @article } | ||
format.json { render json: @article, root: :article } | ||
end | ||
end | ||
|
||
def default_serializer_options | ||
{ root: false } | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
xiongbo/409-active-model-serializers/blog/app/controllers/comments_controller.rb
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,14 @@ | ||
class CommentsController < ApplicationController | ||
def new | ||
@comment = Comment.new | ||
end | ||
|
||
def create | ||
@comment = Comment.new(params[:comment]) | ||
if @comment.save | ||
redirect_to @comment.article, notice: "Successfully created comment." | ||
else | ||
render :new | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
xiongbo/409-active-model-serializers/blog/app/helpers/application_helper.rb
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,7 @@ | ||
module ApplicationHelper | ||
def json_for(target, options = {}) | ||
options[:scope] ||= self | ||
options[:url_options] ||= url_options | ||
target.active_model_serializer.new(target, options).to_json | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
xiongbo/409-active-model-serializers/blog/app/helpers/articles_helper.rb
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 ArticlesHelper | ||
end |
2 changes: 2 additions & 0 deletions
2
xiongbo/409-active-model-serializers/blog/app/helpers/comments_helper.rb
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 CommentsHelper | ||
end |
Empty file.
Empty file.
Oops, something went wrong.