From 6d87cd028b32570973450424db164e5405a0ee13 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 17 Mar 2012 08:32:49 -0700 Subject: moves the guides up to the root directory --- .../getting_started/app/assets/images/rails.png | Bin 0 -> 6646 bytes .../app/assets/javascripts/application.js | 15 ++++ .../app/assets/javascripts/comments.js.coffee | 3 + .../app/assets/javascripts/home.js.coffee | 3 + .../app/assets/javascripts/posts.js.coffee | 3 + .../app/assets/stylesheets/application.css | 13 ++++ .../app/assets/stylesheets/comments.css.scss | 3 + .../app/assets/stylesheets/home.css.scss | 3 + .../app/assets/stylesheets/posts.css.scss | 3 + .../app/assets/stylesheets/scaffolds.css.scss | 56 ++++++++++++++ .../app/controllers/application_controller.rb | 3 + .../app/controllers/comments_controller.rb | 16 ++++ .../app/controllers/home_controller.rb | 5 ++ .../app/controllers/posts_controller.rb | 84 +++++++++++++++++++++ .../app/helpers/application_helper.rb | 2 + .../getting_started/app/helpers/comments_helper.rb | 2 + .../getting_started/app/helpers/home_helper.rb | 2 + .../getting_started/app/helpers/posts_helper.rb | 5 ++ guides/code/getting_started/app/mailers/.gitkeep | 0 guides/code/getting_started/app/models/.gitkeep | 0 guides/code/getting_started/app/models/comment.rb | 3 + guides/code/getting_started/app/models/post.rb | 11 +++ guides/code/getting_started/app/models/tag.rb | 3 + .../app/views/comments/_comment.html.erb | 15 ++++ .../app/views/comments/_form.html.erb | 13 ++++ .../getting_started/app/views/home/index.html.erb | 2 + .../app/views/layouts/application.html.erb | 14 ++++ .../getting_started/app/views/posts/_form.html.erb | 32 ++++++++ .../getting_started/app/views/posts/edit.html.erb | 6 ++ .../getting_started/app/views/posts/index.html.erb | 27 +++++++ .../getting_started/app/views/posts/new.html.erb | 5 ++ .../getting_started/app/views/posts/show.html.erb | 31 ++++++++ .../getting_started/app/views/tags/_form.html.erb | 12 +++ 33 files changed, 395 insertions(+) create mode 100644 guides/code/getting_started/app/assets/images/rails.png create mode 100644 guides/code/getting_started/app/assets/javascripts/application.js create mode 100644 guides/code/getting_started/app/assets/javascripts/comments.js.coffee create mode 100644 guides/code/getting_started/app/assets/javascripts/home.js.coffee create mode 100644 guides/code/getting_started/app/assets/javascripts/posts.js.coffee create mode 100644 guides/code/getting_started/app/assets/stylesheets/application.css create mode 100644 guides/code/getting_started/app/assets/stylesheets/comments.css.scss create mode 100644 guides/code/getting_started/app/assets/stylesheets/home.css.scss create mode 100644 guides/code/getting_started/app/assets/stylesheets/posts.css.scss create mode 100644 guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss create mode 100644 guides/code/getting_started/app/controllers/application_controller.rb create mode 100644 guides/code/getting_started/app/controllers/comments_controller.rb create mode 100644 guides/code/getting_started/app/controllers/home_controller.rb create mode 100644 guides/code/getting_started/app/controllers/posts_controller.rb create mode 100644 guides/code/getting_started/app/helpers/application_helper.rb create mode 100644 guides/code/getting_started/app/helpers/comments_helper.rb create mode 100644 guides/code/getting_started/app/helpers/home_helper.rb create mode 100644 guides/code/getting_started/app/helpers/posts_helper.rb create mode 100644 guides/code/getting_started/app/mailers/.gitkeep create mode 100644 guides/code/getting_started/app/models/.gitkeep create mode 100644 guides/code/getting_started/app/models/comment.rb create mode 100644 guides/code/getting_started/app/models/post.rb create mode 100644 guides/code/getting_started/app/models/tag.rb create mode 100644 guides/code/getting_started/app/views/comments/_comment.html.erb create mode 100644 guides/code/getting_started/app/views/comments/_form.html.erb create mode 100644 guides/code/getting_started/app/views/home/index.html.erb create mode 100644 guides/code/getting_started/app/views/layouts/application.html.erb create mode 100644 guides/code/getting_started/app/views/posts/_form.html.erb create mode 100644 guides/code/getting_started/app/views/posts/edit.html.erb create mode 100644 guides/code/getting_started/app/views/posts/index.html.erb create mode 100644 guides/code/getting_started/app/views/posts/new.html.erb create mode 100644 guides/code/getting_started/app/views/posts/show.html.erb create mode 100644 guides/code/getting_started/app/views/tags/_form.html.erb (limited to 'guides/code/getting_started/app') diff --git a/guides/code/getting_started/app/assets/images/rails.png b/guides/code/getting_started/app/assets/images/rails.png new file mode 100644 index 0000000000..d5edc04e65 Binary files /dev/null and b/guides/code/getting_started/app/assets/images/rails.png differ diff --git a/guides/code/getting_started/app/assets/javascripts/application.js b/guides/code/getting_started/app/assets/javascripts/application.js new file mode 100644 index 0000000000..9097d830e2 --- /dev/null +++ b/guides/code/getting_started/app/assets/javascripts/application.js @@ -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 . diff --git a/guides/code/getting_started/app/assets/javascripts/comments.js.coffee b/guides/code/getting_started/app/assets/javascripts/comments.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/guides/code/getting_started/app/assets/javascripts/comments.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/ diff --git a/guides/code/getting_started/app/assets/javascripts/home.js.coffee b/guides/code/getting_started/app/assets/javascripts/home.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/guides/code/getting_started/app/assets/javascripts/home.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/ diff --git a/guides/code/getting_started/app/assets/javascripts/posts.js.coffee b/guides/code/getting_started/app/assets/javascripts/posts.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/guides/code/getting_started/app/assets/javascripts/posts.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/ diff --git a/guides/code/getting_started/app/assets/stylesheets/application.css b/guides/code/getting_started/app/assets/stylesheets/application.css new file mode 100644 index 0000000000..3b5cc6648e --- /dev/null +++ b/guides/code/getting_started/app/assets/stylesheets/application.css @@ -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 . +*/ diff --git a/guides/code/getting_started/app/assets/stylesheets/comments.css.scss b/guides/code/getting_started/app/assets/stylesheets/comments.css.scss new file mode 100644 index 0000000000..e730912783 --- /dev/null +++ b/guides/code/getting_started/app/assets/stylesheets/comments.css.scss @@ -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/ diff --git a/guides/code/getting_started/app/assets/stylesheets/home.css.scss b/guides/code/getting_started/app/assets/stylesheets/home.css.scss new file mode 100644 index 0000000000..f0ddc6846a --- /dev/null +++ b/guides/code/getting_started/app/assets/stylesheets/home.css.scss @@ -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/ diff --git a/guides/code/getting_started/app/assets/stylesheets/posts.css.scss b/guides/code/getting_started/app/assets/stylesheets/posts.css.scss new file mode 100644 index 0000000000..ed4dfd10f2 --- /dev/null +++ b/guides/code/getting_started/app/assets/stylesheets/posts.css.scss @@ -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/ diff --git a/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss b/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000000..05188f08ed --- /dev/null +++ b/guides/code/getting_started/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; } } diff --git a/guides/code/getting_started/app/controllers/application_controller.rb b/guides/code/getting_started/app/controllers/application_controller.rb new file mode 100644 index 0000000000..e8065d9505 --- /dev/null +++ b/guides/code/getting_started/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery +end diff --git a/guides/code/getting_started/app/controllers/comments_controller.rb b/guides/code/getting_started/app/controllers/comments_controller.rb new file mode 100644 index 0000000000..7447fd078b --- /dev/null +++ b/guides/code/getting_started/app/controllers/comments_controller.rb @@ -0,0 +1,16 @@ +class CommentsController < ApplicationController + http_basic_authenticate_with :name => "dhh", :password => "secret", :only => :destroy + def create + @post = Post.find(params[:post_id]) + @comment = @post.comments.create(params[:comment]) + redirect_to post_path(@post) + end + + def destroy + @post = Post.find(params[:post_id]) + @comment = @post.comments.find(params[:id]) + @comment.destroy + redirect_to post_path(@post) + end + +end diff --git a/guides/code/getting_started/app/controllers/home_controller.rb b/guides/code/getting_started/app/controllers/home_controller.rb new file mode 100644 index 0000000000..6cc31c1ca3 --- /dev/null +++ b/guides/code/getting_started/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ +class HomeController < ApplicationController + def index + end + +end diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb new file mode 100644 index 0000000000..1581d4eb16 --- /dev/null +++ b/guides/code/getting_started/app/controllers/posts_controller.rb @@ -0,0 +1,84 @@ +class PostsController < ApplicationController + http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index + # 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 diff --git a/guides/code/getting_started/app/helpers/application_helper.rb b/guides/code/getting_started/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/guides/code/getting_started/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/guides/code/getting_started/app/helpers/comments_helper.rb b/guides/code/getting_started/app/helpers/comments_helper.rb new file mode 100644 index 0000000000..0ec9ca5f2d --- /dev/null +++ b/guides/code/getting_started/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/guides/code/getting_started/app/helpers/home_helper.rb b/guides/code/getting_started/app/helpers/home_helper.rb new file mode 100644 index 0000000000..23de56ac60 --- /dev/null +++ b/guides/code/getting_started/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/guides/code/getting_started/app/helpers/posts_helper.rb b/guides/code/getting_started/app/helpers/posts_helper.rb new file mode 100644 index 0000000000..b6e8e67894 --- /dev/null +++ b/guides/code/getting_started/app/helpers/posts_helper.rb @@ -0,0 +1,5 @@ +module PostsHelper + def join_tags(post) + post.tags.map { |t| t.name }.join(", ") + end +end diff --git a/guides/code/getting_started/app/mailers/.gitkeep b/guides/code/getting_started/app/mailers/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/guides/code/getting_started/app/models/.gitkeep b/guides/code/getting_started/app/models/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/guides/code/getting_started/app/models/comment.rb b/guides/code/getting_started/app/models/comment.rb new file mode 100644 index 0000000000..4e76c5b5b0 --- /dev/null +++ b/guides/code/getting_started/app/models/comment.rb @@ -0,0 +1,3 @@ +class Comment < ActiveRecord::Base + belongs_to :post +end diff --git a/guides/code/getting_started/app/models/post.rb b/guides/code/getting_started/app/models/post.rb new file mode 100644 index 0000000000..61c2b5ae44 --- /dev/null +++ b/guides/code/getting_started/app/models/post.rb @@ -0,0 +1,11 @@ +class Post < ActiveRecord::Base + validates :name, :presence => true + validates :title, :presence => true, + :length => { :minimum => 5 } + + has_many :comments, :dependent => :destroy + has_many :tags + + accepts_nested_attributes_for :tags, :allow_destroy => :true, + :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } +end diff --git a/guides/code/getting_started/app/models/tag.rb b/guides/code/getting_started/app/models/tag.rb new file mode 100644 index 0000000000..30992e8ba9 --- /dev/null +++ b/guides/code/getting_started/app/models/tag.rb @@ -0,0 +1,3 @@ +class Tag < ActiveRecord::Base + belongs_to :post +end diff --git a/guides/code/getting_started/app/views/comments/_comment.html.erb b/guides/code/getting_started/app/views/comments/_comment.html.erb new file mode 100644 index 0000000000..4c3fbf26cd --- /dev/null +++ b/guides/code/getting_started/app/views/comments/_comment.html.erb @@ -0,0 +1,15 @@ +

+ Commenter: + <%= comment.commenter %> +

+ +

+ Comment: + <%= comment.body %> +

+ +

+ <%= link_to 'Destroy Comment', [comment.post, comment], + :confirm => 'Are you sure?', + :method => :delete %> +

diff --git a/guides/code/getting_started/app/views/comments/_form.html.erb b/guides/code/getting_started/app/views/comments/_form.html.erb new file mode 100644 index 0000000000..d15bdd6b59 --- /dev/null +++ b/guides/code/getting_started/app/views/comments/_form.html.erb @@ -0,0 +1,13 @@ +<%= form_for([@post, @post.comments.build]) do |f| %> +
+ <%= f.label :commenter %>
+ <%= f.text_field :commenter %> +
+
+ <%= f.label :body %>
+ <%= f.text_area :body %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/guides/code/getting_started/app/views/home/index.html.erb b/guides/code/getting_started/app/views/home/index.html.erb new file mode 100644 index 0000000000..bb4f3dcd1f --- /dev/null +++ b/guides/code/getting_started/app/views/home/index.html.erb @@ -0,0 +1,2 @@ +

Hello, Rails!

+<%= link_to "My Blog", posts_path %> diff --git a/guides/code/getting_started/app/views/layouts/application.html.erb b/guides/code/getting_started/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..6578a41da2 --- /dev/null +++ b/guides/code/getting_started/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Blog + <%= stylesheet_link_tag "application", :media => "all" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/posts/_form.html.erb new file mode 100644 index 0000000000..e27da7f413 --- /dev/null +++ b/guides/code/getting_started/app/views/posts/_form.html.erb @@ -0,0 +1,32 @@ +<% @post.tags.build %> +<%= form_for(@post) do |post_form| %> + <% if @post.errors.any? %> +
+

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

+ +
+ <% end %> + +
+ <%= post_form.label :name %>
+ <%= post_form.text_field :name %> +
+
+ <%= post_form.label :title %>
+ <%= post_form.text_field :title %> +
+
+ <%= post_form.label :content %>
+ <%= post_form.text_area :content %> +
+

Tags

+ <%= render :partial => 'tags/form', + :locals => {:form => post_form} %> +
+ <%= post_form.submit %> +
+<% end %> diff --git a/guides/code/getting_started/app/views/posts/edit.html.erb b/guides/code/getting_started/app/views/posts/edit.html.erb new file mode 100644 index 0000000000..720580236b --- /dev/null +++ b/guides/code/getting_started/app/views/posts/edit.html.erb @@ -0,0 +1,6 @@ +

Editing post

+ +<%= render 'form' %> + +<%= link_to 'Show', @post %> | +<%= link_to 'Back', posts_path %> diff --git a/guides/code/getting_started/app/views/posts/index.html.erb b/guides/code/getting_started/app/views/posts/index.html.erb new file mode 100644 index 0000000000..45dee1b25f --- /dev/null +++ b/guides/code/getting_started/app/views/posts/index.html.erb @@ -0,0 +1,27 @@ +

Listing posts

+ + + + + + + + + + + +<% @posts.each do |post| %> + + + + + + + + +<% end %> +
NameTitleContent
<%= post.name %><%= post.title %><%= post.content %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Post', new_post_path %> diff --git a/guides/code/getting_started/app/views/posts/new.html.erb b/guides/code/getting_started/app/views/posts/new.html.erb new file mode 100644 index 0000000000..36ad7421f9 --- /dev/null +++ b/guides/code/getting_started/app/views/posts/new.html.erb @@ -0,0 +1,5 @@ +

New post

+ +<%= render 'form' %> + +<%= link_to 'Back', posts_path %> diff --git a/guides/code/getting_started/app/views/posts/show.html.erb b/guides/code/getting_started/app/views/posts/show.html.erb new file mode 100644 index 0000000000..da78a9527b --- /dev/null +++ b/guides/code/getting_started/app/views/posts/show.html.erb @@ -0,0 +1,31 @@ +

<%= notice %>

+ +

+ Name: + <%= @post.name %> +

+ +

+ Title: + <%= @post.title %> +

+ +

+ Content: + <%= @post.content %> +

+ +

+ Tags: + <%= join_tags(@post) %> +

+ +

Comments

+<%= render @post.comments %> + +

Add a comment:

+<%= render "comments/form" %> + + +<%= link_to 'Edit Post', edit_post_path(@post) %> | +<%= link_to 'Back to Posts', posts_path %> | diff --git a/guides/code/getting_started/app/views/tags/_form.html.erb b/guides/code/getting_started/app/views/tags/_form.html.erb new file mode 100644 index 0000000000..7e424b0e20 --- /dev/null +++ b/guides/code/getting_started/app/views/tags/_form.html.erb @@ -0,0 +1,12 @@ +<%= form.fields_for :tags do |tag_form| %> +
+ <%= tag_form.label :name, 'Tag:' %> + <%= tag_form.text_field :name %> +
+ <% unless tag_form.object.nil? || tag_form.object.new_record? %> +
+ <%= tag_form.label :_destroy, 'Remove:' %> + <%= tag_form.check_box :_destroy %> +
+ <% end %> +<% end %> -- cgit v1.2.3