aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/getting_started.textile
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-02-06 02:25:55 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-02-06 02:25:55 +0000
commitb9ba2fe55059a6d9f141d1d502e16bdfd46f26cb (patch)
tree491c3ce7d406a723e5c06e3bccf4559a0de86199 /railties/guides/source/getting_started.textile
parent97612394672203eefd04e3b1947273a3ab4ec930 (diff)
parent96d610553e5fdaabc923835ab1f194070ddb4477 (diff)
downloadrails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.tar.gz
rails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.tar.bz2
rails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.zip
Merge commit 'mainstream/master'
Conflicts: railties/guides/files/javascripts/code_highlighter.js railties/guides/files/javascripts/guides.js railties/guides/files/javascripts/highlighters.js railties/guides/files/stylesheets/main.css railties/guides/files/stylesheets/print.css railties/guides/files/stylesheets/reset.css railties/guides/files/stylesheets/style.css railties/guides/files/stylesheets/syntax.css railties/guides/rails_guides/indexer.rb railties/guides/source/2_2_release_notes.textile railties/guides/source/2_3_release_notes.textile railties/guides/source/action_controller_overview.textile railties/guides/source/action_mailer_basics.textile railties/guides/source/active_record_basics.textile railties/guides/source/activerecord_validations_callbacks.textile railties/guides/source/association_basics.textile railties/guides/source/caching_with_rails.textile railties/guides/source/command_line.textile railties/guides/source/debugging_rails_applications.textile railties/guides/source/form_helpers.textile railties/guides/source/getting_started.textile railties/guides/source/i18n.textile railties/guides/source/layout.html.erb railties/guides/source/layouts_and_rendering.textile railties/guides/source/migrations.textile railties/guides/source/performance_testing.textile railties/guides/source/plugins.textile railties/guides/source/rails_on_rack.textile railties/guides/source/routing.textile railties/guides/source/security.textile railties/guides/source/testing.textile
Diffstat (limited to 'railties/guides/source/getting_started.textile')
-rw-r--r--railties/guides/source/getting_started.textile40
1 files changed, 20 insertions, 20 deletions
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index bdd2a9d429..3163fdb4bc 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -248,7 +248,7 @@ Now that you have your database configured, it's time to have Rails create an em
$ rake db:create
</shell>
-NOTE. Rake is a general-purpose command-runner that Rails uses for many things. You can see the list of available rake commands in your application by running +rake -T+.
+NOTE. Rake is a general-purpose command-runner that Rails uses for many things. You can see the list of available rake commands in your application by running +rake -T+.
h3. Hello, Rails!
@@ -313,7 +313,7 @@ NOTE. For more information about routing, refer to "Rails Routing from the Outsi
h3. Getting Up and Running Quickly With Scaffolding
-Rails _scaffolding_ is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.
+Rails _scaffolding_ is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.
h3. Creating a Resource
@@ -440,14 +440,14 @@ After the console loads, you can use it to work with your application's models:
<shell>
>> p = Post.create(:content => "A new post")
-=> #<Post id: nil, name: nil, title: nil, content: "A new post",
+=> #<Post id: nil, name: nil, title: nil, content: "A new post",
created_at: nil, updated_at: nil>
>> p.save
=> false
>> p.errors
-=> #<ActiveRecord::Errors:0x23bcf0c @base=#<Post id: nil, name: nil,
-title: nil, content: "A new post", created_at: nil, updated_at: nil>,
-@errors={"name"=>["can't be blank"], "title"=>["can't be blank",
+=> #<ActiveRecord::Errors:0x23bcf0c @base=#<Post id: nil, name: nil,
+title: nil, content: "A new post", created_at: nil, updated_at: nil>,
+@errors={"name"=>["can't be blank"], "title"=>["can't be blank",
"is too short (minimum is 5 characters)"]}>
</shell>
@@ -493,7 +493,7 @@ The +respond_to+ block handles both HTML and XML calls to this action. If you br
<td><%=h 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?',
+ <td><%= link_to 'Destroy', post, :confirm => 'Are you sure?',
:method => :delete %></td>
</tr>
<% end %>
@@ -522,7 +522,7 @@ The view is only part of the story of how HTML is displayed in your web browser.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
- <meta http-equiv="content-type"
+ <meta http-equiv="content-type"
content="text/html;charset=UTF-8" />
<title>Posts: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
@@ -596,11 +596,11 @@ def create
if @post.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to(@post) }
- format.xml { render :xml => @post, :status => :created,
+ format.xml { render :xml => @post, :status => :created,
:location => @post }
else
format.html { render :action => "new" }
- format.xml { render :xml => @post.errors,
+ format.xml { render :xml => @post.errors,
:status => :unprocessable_entity }
end
end
@@ -701,7 +701,7 @@ def update
format.xml { head :ok }
else
format.html { render :action => "edit" }
- format.xml { render :xml => @post.errors,
+ format.xml { render :xml => @post.errors,
:status => :unprocessable_entity }
end
end
@@ -796,7 +796,7 @@ class PostsController < ApplicationController
# ...
def show
@post = Post.find(params[:id])
- # ...
+ # ...
end
def edit
@@ -819,11 +819,11 @@ Four instances of the exact same line of code doesn’t seem very DRY. Rails pro
<ruby>
class PostsController < ApplicationController
- before_filter :find_post,
+ before_filter :find_post,
:only => [:show, :edit, :update, :destroy]
# ...
def show
- # ...
+ # ...
end
def edit
@@ -852,12 +852,12 @@ h3. Adding a Second Model
Now that you've seen what's in a model built with scaffolding, it's time to add a second model to the application. The second model will handle comments on blog posts.
-h4. Generating a Model
+h4. Generating a Model
Models in Rails use a singular name, and their corresponding database tables use a plural name. For the model to hold comments, the convention is to use the name Comment. Even if you don't want to use the entire apparatus set up by scaffolding, most Rails developers still use generators to make things like models and controllers. To create the new model, run this command in your terminal:
<shell>
-$ script/generate model Comment commenter:string body:text
+$ script/generate model Comment commenter:string body:text
post:references
</shell>
@@ -1011,7 +1011,7 @@ class CommentsController < ApplicationController
render :action => "new"
end
end
-
+
def edit
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
@@ -1075,7 +1075,7 @@ The +views/comments/index.html.erb+ view:
<%= link_to 'Edit', edit_post_comment_path(@post, comment) %>
</td>
<td>
- <%= link_to 'Destroy', post_comment_path(@post, comment),
+ <%= link_to 'Destroy', post_comment_path(@post, comment),
:confirm => 'Are you sure?', :method => :delete %>
</td>
</tr>
@@ -1220,7 +1220,7 @@ class Post < ActiveRecord::Base
validates_length_of :title, :minimum => 5
has_many :comments
has_many :tags
-
+
accepts_nested_attributes_for :tags, :allow_destroy => :true ,
:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end
@@ -1294,4 +1294,4 @@ h3. Changelog
* October 16, 2008: Revised based on feedback from Pratik Naik by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)
* October 13, 2008: First complete draft by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)
* October 12, 2008: More detail, rearrangement, editing by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)
-* September 8, 2008: initial version by James Miller (not yet approved for publication) \ No newline at end of file
+* September 8, 2008: initial version by James Miller (not yet approved for publication)