1. YOUR FIRST RAILS APP
Environments, MVC, Scaffold
Sunday, November 13, 11
2. CREATING YOUR FIRST RAILS APP
rails new roster
This command generates code for
a new Rails web application
in a sub-directory called “roster”
Sunday, November 13, 11
3. THE APPLICATION DIRECTORY
• The whole rails app is in this one directory
• No hidden configuration files in system directories
• You will modify many of these files in the course of your development
• We're using sqlite so even the database is in this directory, but usually the
database is the only part of your application that lives somewhere else
• You can simple copy this directory to server to deploy the app
• You can delete the directory and its contents
if you want to throw it away and start over
Sunday, November 13, 11
4. RUNNING YOUR APP
cd roster
bundle
rails server
Sunday, November 13, 11
5. RAILS ENVIRONMENTS
By default, Rails is configured with 3 environments:
• development
• test
• production
Sunday, November 13, 11
8. RAILS ENVIRONMENTS
The environment can be specified with
RAILS_ENV as an environment variable
"development" by default.
In your code, you refer to Rails.env
(or RAILS_ENV in Rails 2)
Sunday, November 13, 11
11. MODIFYING THE HOME PAGE
public/index.html
All files in the public directory
are static content.
Rails checks this directory
before executing any dynamic code.
Sunday, November 13, 11
16. MVC
Model: ActiveRecord
•Represents what is in the database
View: ActionView, erb
•Model rendered as HTML
Controller: ActionController
•Receives HTTP actions (GET, POST, PUT, DELETE)
•Decides what to do, typically rendering a view
Sunday, November 13, 11
17. VIEWS
<% @people.each do |person| %>
<tr>
<td><%= person.first_name %></td>
<td><%= person.last_name %></td>
</tr>
<% end %>
Sunday, November 13, 11
18. VIEW EXERCISE
On the main people page
a. Change “Listing people” to “My Class List”
b. List people with first initial and last name in one visual
column (e.g. W. Flintstone)
Sunday, November 13, 11