aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/source/getting_started_with_rails.txt
diff options
context:
space:
mode:
Diffstat (limited to 'railties/doc/guides/source/getting_started_with_rails.txt')
-rw-r--r--railties/doc/guides/source/getting_started_with_rails.txt32
1 files changed, 24 insertions, 8 deletions
diff --git a/railties/doc/guides/source/getting_started_with_rails.txt b/railties/doc/guides/source/getting_started_with_rails.txt
index bae8f9a4fd..b66d2f6f9e 100644
--- a/railties/doc/guides/source/getting_started_with_rails.txt
+++ b/railties/doc/guides/source/getting_started_with_rails.txt
@@ -154,6 +154,13 @@ And if you're using PostgreSQL for data storage, run this command:
$ rails blog -d postgresql
-------------------------------------------------------
+After you create the blog application, switch to its folder to continue work directly in that application:
+
+[source, shell]
+-------------------------------------------------------
+$ cd blog
+-------------------------------------------------------
+
In any case, Rails will create a folder in your working directory called +blog+. Open up that folder and explore its contents. Most of the work in this tutorial will happen in the +app/+ folder, but here's a basic rundown on the function of each folder that Rails creates in a new application by default:
[grid="all"]
@@ -239,6 +246,15 @@ development:
Change the username and password in the +development+ section as appropriate.
+==== Creating the Database
+
+Now that you have your database configured, it's time to have Rails create an empty database for you. You can do this by running a rake command:
+
+[source, shell]
+-------------------------------------------------------
+$ rake db:create
+-------------------------------------------------------
+
== Hello, Rails!
One of the traditional places to start with a new language is by getting some text up on screen quickly. To do that in Rails, you need to create at minimum a controller and a view. Fortunately, you can do that in a single command. Enter this command in your terminal:
@@ -370,7 +386,7 @@ end
If you were to translate that into words, it says something like: when this migration is run, create a table named +posts+ with two string columns (+name+ and +title+) and a text column (+content+), and generate timestamp fields to track record creation and updating. You can learn the detailed syntax for migrations in the link:../migrations.html[Rails Database Migrations] guide.
-At this point, you need to do two things: create the database and run the migration. You can use rake commands at the terminal for both of those tasks:
+At this point, you can use a rake command to run the migration:
[source, shell]
-------------------------------------------------------
@@ -378,7 +394,7 @@ $ rake db:create
$ rake db:migrate
-------------------------------------------------------
-NOTE: Because you're working in the development environment by default, both of these commands will apply to the database defined in the +development+ section of your +config/database.yml+ file.
+NOTE: Because you're working in the development environment by default, this command will apply to the database defined in the +development+ section of your +config/database.yml+ file.
=== Adding a Link
@@ -748,7 +764,7 @@ At this point, it’s worth looking at some of the tools that Rails provides to
=== Using Partials to Eliminate View Duplication
-As you saw earlier, the scaffold-generated views for the +new+ and +edit+ actions are largely identical. You can pull the shared code out into a +partial+ template. This requires editing the new and edit views, and adding a new template:
+As you saw earlier, the scaffold-generated views for the +new+ and +edit+ actions are largely identical. You can pull the shared code out into a +partial+ template. This requires editing the new and edit views, and adding a new template. The new +_form.html.erb+ template should be saved in the same +app/views/posts+ folder as the files from which it is being extracted:
+new.html.erb+:
@@ -1021,7 +1037,7 @@ class CommentsController < ApplicationController
def show
@post = Post.find(params[:post_id])
- @comment = Comment.find(params[:id])
+ @comment = @post.comments.find(params[:id])
end
def new
@@ -1033,7 +1049,7 @@ class CommentsController < ApplicationController
@post = Post.find(params[:post_id])
@comment = @post.comments.build(params[:comment])
if @comment.save
- redirect_to post_comment_path(@post, @comment)
+ redirect_to post_comment_url(@post, @comment)
else
render :action => "new"
end
@@ -1041,14 +1057,14 @@ class CommentsController < ApplicationController
def edit
@post = Post.find(params[:post_id])
- @comment = Comment.find(params[:id])
+ @comment = @post.comments.find(params[:id])
end
def update
@post = Post.find(params[:post_id])
@comment = Comment.find(params[:id])
if @comment.update_attributes(params[:comment])
- redirect_to post_comment_path(@post, @comment)
+ redirect_to post_comment_url(@post, @comment)
else
render :action => "edit"
end
@@ -1219,7 +1235,7 @@ Note that each post has its own individual comments collection, accessible as +@
Now that you've seen your first Rails application, you should feel free to update it and experiment on your own. But you don't have to do everything without help. As you need assistance getting up and running with Rails, feel free to consult these support resources:
-* The link:http://manuals.rubyonrails.org/[Ruby On Rails guides]
+* The link:http://guides.rubyonrails.org/[Ruby On Rails guides]
* The link:http://groups.google.com/group/rubyonrails-talk[Ruby on Rails mailing list]
* The #rubyonrails channel on irc.freenode.net
* The link:http://wiki.rubyonrails.org/rails[Rails wiki]