Permalink
Browse files

Merge branch 'master' of github.com:lifo/docrails

  • Loading branch information...
vijaydev committed Apr 21, 2012
2 parents ed81083 + c670b57 commit a719843d31042690fa4fa8f55bc8a647d360b2a8
Showing with 391 additions and 314 deletions.
  1. +2 −2 actionpack/lib/action_dispatch/routing/redirection.rb
  2. +1 −1 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  3. +1 −1 actionpack/lib/action_view/helpers/form_helper.rb
  4. +2 −0 activemodel/lib/active_model/observing.rb
  5. BIN guides/assets/images/getting_started/form_with_errors.png
  6. BIN guides/assets/images/getting_started/show_action_for_posts.png
  7. BIN guides/assets/images/posts_index.png
  8. +3 −3 guides/code/getting_started/Gemfile
  9. +0 −3 guides/code/getting_started/app/assets/javascripts/comments.js.coffee
  10. +0 −3 guides/code/getting_started/app/assets/javascripts/home.js.coffee
  11. +0 −3 guides/code/getting_started/app/assets/javascripts/posts.js.coffee
  12. +0 −3 guides/code/getting_started/app/assets/stylesheets/comments.css.scss
  13. +0 −3 guides/code/getting_started/app/assets/stylesheets/home.css.scss
  14. +0 −3 guides/code/getting_started/app/assets/stylesheets/posts.css.scss
  15. +0 −56 guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss
  16. +1 −1 guides/code/getting_started/app/controllers/home_controller.rb
  17. +5 −65 guides/code/getting_started/app/controllers/posts_controller.rb
  18. +1 −1 guides/code/getting_started/app/helpers/home_helper.rb
  19. +0 −3 guides/code/getting_started/app/helpers/posts_helper.rb
  20. +1 −6 guides/code/getting_started/app/models/post.rb
  21. +0 −3 guides/code/getting_started/app/models/tag.rb
  22. +0 −2 guides/code/getting_started/app/views/home/index.html.erb
  23. +22 −29 guides/code/getting_started/app/views/posts/_form.html.erb
  24. +5 −13 guides/code/getting_started/app/views/posts/index.html.erb
  25. +1 −1 guides/code/getting_started/app/views/posts/new.html.erb
  26. +6 −26 guides/code/getting_started/app/views/posts/show.html.erb
  27. +0 −12 guides/code/getting_started/app/views/tags/_form.html.erb
  28. +2 −0 guides/code/getting_started/app/views/welcome/index.html.erb
  29. +9 −6 guides/code/getting_started/config/routes.rb
  30. +0 −11 guides/code/getting_started/db/migrate/20110901013701_create_tags.rb
  31. +1 −2 ...code/getting_started/db/migrate/{20110901012504_create_posts.rb → 20120420083127_create_posts.rb}
  32. +8 −9 guides/code/getting_started/db/schema.rb
  33. +2 −4 guides/code/getting_started/test/fixtures/posts.yml
  34. +1 −1 guides/code/getting_started/test/functional/home_controller_test.rb
  35. 0 guides/code/getting_started/vendor/assets/stylesheets/.gitkeep
  36. +7 −0 guides/source/configuring.textile
  37. +1 −1 guides/source/form_helpers.textile
  38. +307 −37 guides/source/getting_started.textile
  39. +2 −0 guides/source/migrations.textile
@@ -72,8 +72,8 @@ module Redirection
# "http://#{request.host_with_port}/#{path}"
# }
#
- # Note that the `do end` syntax for the redirect block wouldn't work, as Ruby would pass
- # the block to `match` instead of `redirect`. Use `{ ... }` instead.
+ # Note that the +do end+ syntax for the redirect block wouldn't work, as Ruby would pass
+ # the block to +match+ instead of +redirect+. Use <tt>{ ... }</tt> instead.
#
# The options version of redirect allows you to supply only the parts of the url which need
# to change, it also supports interpolation of the path similar to the first example.
@@ -442,7 +442,7 @@ def image_alt(src)
# <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
# video_tag(["trailer.ogg", "trailer.flv"]) # =>
# <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
- # video_tag(["trailer.ogg", "trailer.flv"] :size => "160x120") # =>
+ # video_tag(["trailer.ogg", "trailer.flv"], :size => "160x120") # =>
# <video height="120" width="160"><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
def video_tag(*sources)
multiple_sources_tag('video', sources) do |options|
@@ -184,7 +184,7 @@ def convert_to_model(object)
# First name: <%= f.text_field :first_name %>
# Last name : <%= f.text_field :last_name %>
# Biography : <%= text_area :person, :biography %>
- # Admin? : <%= check_box_tag "person[admin]", @person.company.admin? %>
+ # Admin? : <%= check_box_tag "person[admin]", "1", @person.company.admin? %>
# <%= f.submit %>
# <% end %>
#
@@ -214,6 +214,7 @@ def observed_class
end
# Start observing the declared classes and their subclasses.
+ # Called automatically by the instance method.
def initialize
observed_classes.each { |klass| add_observer!(klass) }
end
@@ -242,6 +243,7 @@ def add_observer!(klass) #:nodoc:
klass.add_observer(self)
end
+ # Returns true if notifications are disabled for this object.
def disabled_for?(object)
klass = object.class
return false unless klass.respond_to?(:observers)
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
source 'https://rubygems.org'
-gem 'rails', '3.2.0'
+gem 'rails', '3.2.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
@@ -15,7 +15,7 @@ group :assets do
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
- # gem 'therubyracer'
+ # gem 'therubyracer', :platform => :ruby
gem 'uglifier', '>= 1.0.3'
end
@@ -28,7 +28,7 @@ gem 'jquery-rails'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
-# Use unicorn as the web server
+# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
@@ -1,3 +0,0 @@
-# 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/
@@ -1,3 +0,0 @@
-# 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/
@@ -1,3 +0,0 @@
-# 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/
@@ -1,3 +0,0 @@
-// 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/
@@ -1,3 +0,0 @@
-// 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/
@@ -1,3 +0,0 @@
-// 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/
@@ -1,56 +0,0 @@
-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; } }
@@ -1,4 +1,4 @@
-class HomeController < ApplicationController
+class WelcomeController < ApplicationController
def index
end
@@ -1,84 +1,24 @@
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 }
+ if @post.save
+ redirect_to :action => :show, :id => @post.id
+ else
+ render 'new'
end
end
end
@@ -1,2 +1,2 @@
-module HomeHelper
+module WelcomeHelper
end
@@ -1,5 +1,2 @@
module PostsHelper
- def join_tags(post)
- post.tags.map { |t| t.name }.join(", ")
- end
end
@@ -1,11 +1,6 @@
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
@@ -1,3 +0,0 @@
-class Tag < ActiveRecord::Base
- belongs_to :post
-end
@@ -1,2 +0,0 @@
-<h1>Hello, Rails!</h1>
-<%= link_to "My Blog", posts_path %>
@@ -1,32 +1,25 @@
-<% @post.tags.build %>
-<%= form_for(@post) do |post_form| %>
+<%= form_for :post, :url => { :action => :create } do |f| %>
<% if @post.errors.any? %>
- <div id="errorExplanation">
- <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>
+ <div id="errorExplanation">
+ <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">
- <%= post_form.label :name %><br />
- <%= post_form.text_field :name %>
- </div>
- <div class="field">
- <%= post_form.label :title %><br />
- <%= post_form.text_field :title %>
- </div>
- <div class="field">
- <%= post_form.label :content %><br />
- <%= post_form.text_area :content %>
- </div>
- <h2>Tags</h2>
- <%= render :partial => 'tags/form',
- :locals => {:form => post_form} %>
- <div class="actions">
- <%= post_form.submit %>
- </div>
+ <p>
+ <%= f.label :title %><br>
+ <%= f.text_field :title %>
+ </p>
+
+ <p>
+ <%= f.label :text %><br>
+ <%= f.text_area :text %>
+ </p>
+
+ <p>
+ <%= f.submit %>
+ </p>
<% end %>
@@ -1,27 +1,19 @@
<h1>Listing posts</h1>
+<%= link_to 'New post', :action => :new %>
+
<table>
<tr>
- <th>Name</th>
<th>Title</th>
- <th>Content</th>
- <th></th>
- <th></th>
+ <th>Text</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, confirm: 'Are you sure?', method: :delete %></td>
+ <td><%= post.text %></td>
+ <td><%= link_to 'Show', :action => :show, :id => post.id %>
</tr>
<% end %>
</table>
-
-<br />
-
-<%= link_to 'New Post', new_post_path %>
@@ -2,4 +2,4 @@
<%= render 'form' %>
-<%= link_to 'Back', posts_path %>
+<%= link_to 'Back', :action => :index %>
Oops, something went wrong.

0 comments on commit a719843

Please sign in to comment.