/
COMMANDS
120 lines (75 loc) · 2.66 KB
/
COMMANDS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Download Rails 2.1
sudo gem install rails
# Generate a default rails 2.1 application
rails lava_time
# Using the built-in code generators make a time_entry table.
script/generate scaffold TimeEntry start_time:datetime end_time:datetime
# Update the database.
rake db:migrate
# Remove the default index page, because direct requests to index.html have higher priority over Rails's routing system. (This priority is defined in /public/.htaccess )
mv public/index.html public/index.html.default
# Modify the default route in routes.rb
map.root :controller => "time_entries"
# Start your server.
ruby script/server
# In your browser, go to http://localhost:3000/
# Install Rspec
# From: http://github.com/dchelimsky/rspec-rails/wikis/home
# Also see rspec.info for more info about RSpec.
cd vendor/plugins
git clone git://github.com/dchelimsky/rspec.git
git clone git://github.com/dchelimsky/rspec-rails.git
cd rspec
git checkout 1.1.4
cd ../rspec-rails
git checkout 1.1.4
cd ..
rm -rf rspec/.git
rm -rf rspec-rails/.git
cd ../../
script/generate rspec
# Check it back into your local git repository.
git add .
gc -m 'Checking in RSpec plugin'
# Upload it to the origin server.
git push origin master
# Installing restful_authentication
# For a tutorial on how to use it: http://railscasts.com/episodes/67
cd vendor/plugins
git clone git://github.com/technoweenie/restful-authentication.git
cd restful-authentication
git co master
cd ../..
git add .
gc -m 'installed restful_authentication plugin'
# Update github.com server
git push origin master
# Run the generator for restful_authentication to generate the User and Session models.
./script/generate authenticated user sessions --rspec
# Run the migration to create the `users` table:
rake db:migrate
# Move this line of code into the ApplicationController.
include AuthenticatedSystem
# Restart the web server cuz the web server only reads ApplicationController once during start up.
# In the User model:
has_many :time_entries
# In the TimeEntry model:
belongs_to :user
# in the TimeEntriesController's index action:
@time_entries = current_user.time_entries
# Generate a migration file to add the :user_id field to TimeEntries
script/generate migration TimeEntryBelongsToUser
# Inside the migration file db/20080805120650_time_entry_belongs_to_user.rb, in self.up definition:
change_table :time_entries do |t|
t.integer :user_id
end
# and in self.down
change_table :time_entries do |t|
t.remove :user_id
end
# Run the migration.
rake db:migrate
# In TimeEntriesController in the create action and update action:
@time_entry.user_id = current_user.id if logged_in?
# Restart the web server.
ruby script/server -p 3000