induction_cannon_01 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +7 -1
- data/Gemfile.lock +22 -2
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/app/controllers/users_controller.rb +3 -78
- data/app/models/user.rb +1 -0
- data/config/routes.rb +12 -58
- data/induction_cannon_01.gemspec +23 -11
- data/lib/tasks/custom.rake +7 -0
- data/pkg/induction_cannon_01-0.0.2.gem +0 -0
- data/public/javascripts/jquery.js +8316 -0
- data/public/javascripts/jquery.min.js +16 -0
- data/public/javascripts/rails.js +157 -191
- data/spec/controllers/users_controller_spec.rb +30 -0
- data/spec/factories/user.rb +5 -0
- data/spec/models/base/search_spec.rb +72 -0
- data/spec/models/base/transaction_spec.rb +44 -0
- data/spec/models/user_spec.rb +2 -69
- data/spec/spec_helper.rb +3 -8
- metadata +59 -23
- data/README +0 -256
- data/public/javascripts/controls.js +0 -965
- data/public/javascripts/dragdrop.js +0 -974
- data/public/javascripts/effects.js +0 -1123
- data/public/javascripts/prototype.js +0 -6001
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UsersController do
|
4
|
+
describe "current_identifier" do
|
5
|
+
it '01' do
|
6
|
+
get :index
|
7
|
+
@controller.send(:current_identifier).should == "user"
|
8
|
+
@controller.send(:current_model).should == User
|
9
|
+
end
|
10
|
+
|
11
|
+
it '02' do
|
12
|
+
Factory(:user)
|
13
|
+
|
14
|
+
get :show, :id => 1
|
15
|
+
@controller.send(:current_identifier).should == "user"
|
16
|
+
@controller.send(:current_model).should == User
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "base_action" do
|
21
|
+
it '01' do
|
22
|
+
ids = [Factory(:user), Factory(:user)].map(&:id)
|
23
|
+
@request.env["HTTP_REFERER"] = users_path
|
24
|
+
|
25
|
+
put :update_all, :ids => ids
|
26
|
+
|
27
|
+
flash.notice.should == "The operation was successful"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
describe 'regexp' do
|
5
|
+
it '01' do
|
6
|
+
user1 = User.create(:info => "cool")
|
7
|
+
user2 = User.create(:info => "hello")
|
8
|
+
|
9
|
+
result = User.regexp(:info, "ll")
|
10
|
+
|
11
|
+
result.should have(1).user
|
12
|
+
result.first.should == user2
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
it '02' do
|
17
|
+
User.create(:info => "cool")
|
18
|
+
User.create(:info => "hello")
|
19
|
+
|
20
|
+
result = User.regexp(:info, "olo")
|
21
|
+
|
22
|
+
result.should have(0).user
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'fuzzy search' do
|
27
|
+
it '01' do
|
28
|
+
user1 = User.create(:info => "cool")
|
29
|
+
user2 = User.create(:info => "hello")
|
30
|
+
|
31
|
+
result = User.fuzzy(User => {:info => "ll"})
|
32
|
+
result.should have(1).user
|
33
|
+
result.first.should == user2
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
it '02' do
|
38
|
+
User.create(:info => "cool")
|
39
|
+
User.create(:info => "hello")
|
40
|
+
|
41
|
+
result = User.fuzzy(User => {:info => "olo"})
|
42
|
+
result.should have(0).user
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
it '03' do
|
47
|
+
User.create(:info => "cool")
|
48
|
+
User.create(:info => "hello")
|
49
|
+
|
50
|
+
result = User.fuzzy(User => {:info => "l"})
|
51
|
+
|
52
|
+
User.all.should have(2).user
|
53
|
+
result.should have(2).user
|
54
|
+
end
|
55
|
+
|
56
|
+
it '04' do
|
57
|
+
user = User.create(:info => "cool")
|
58
|
+
User.create(:info => "hello")
|
59
|
+
user.blogs.create(:title => "yeah")
|
60
|
+
|
61
|
+
result = User.includes(:blogs).fuzzy(User => {:info => "lll"}, Blog => {:title => "y"})
|
62
|
+
|
63
|
+
result.should have(1).user
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
describe "Transaction" do
|
2
|
+
it "01" do
|
3
|
+
param = mock.blank? {true}
|
4
|
+
User.each_with_transaction(param).should == :empty
|
5
|
+
end
|
6
|
+
|
7
|
+
it '02' do
|
8
|
+
5.times { Factory(:user) }
|
9
|
+
ids = User.all.map(&:id)
|
10
|
+
ids << (ids.last + 10)
|
11
|
+
|
12
|
+
User.each_with_transaction(ids).should == :error
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
it '03' do
|
17
|
+
5.times { Factory(:user) }
|
18
|
+
ids = User.all.map(&:id)
|
19
|
+
|
20
|
+
User.each_with_transaction(ids) do |user|
|
21
|
+
user.update_attributes(:name => "cool")
|
22
|
+
end.should == :success
|
23
|
+
|
24
|
+
User.all.map(&:name).all? {|name| name == "cool"}.should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
it '04' do
|
30
|
+
user = Factory(:user, :name => "i" * 100)
|
31
|
+
user.should be_persisted
|
32
|
+
|
33
|
+
params = {:name => "cool"}
|
34
|
+
mock.instance_of(User).update_attributes(params) { false }
|
35
|
+
|
36
|
+
|
37
|
+
User.each_with_transaction([user.id]) do |user|
|
38
|
+
user.update_attributes(params)
|
39
|
+
end.should == :error
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end
|
data/spec/models/user_spec.rb
CHANGED
@@ -1,72 +1,5 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe User do
|
4
|
-
|
5
|
-
|
6
|
-
user1 = User.create(:info => "cool")
|
7
|
-
user2 = User.create(:info => "hello")
|
8
|
-
|
9
|
-
result = User.regexp(:info, "ll")
|
10
|
-
|
11
|
-
result.should have(1).user
|
12
|
-
result.first.should == user2
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
it '02' do
|
17
|
-
User.create(:info => "cool")
|
18
|
-
User.create(:info => "hello")
|
19
|
-
|
20
|
-
result = User.regexp(:info, "olo")
|
21
|
-
|
22
|
-
result.should have(0).user
|
23
|
-
end
|
2
|
+
it 'is valid' do
|
3
|
+
Factory(:user).should be_persisted
|
24
4
|
end
|
25
|
-
|
26
|
-
describe 'fuzzy search' do
|
27
|
-
it '01' do
|
28
|
-
user1 = User.create(:info => "cool")
|
29
|
-
user2 = User.create(:info => "hello")
|
30
|
-
|
31
|
-
result = User.fuzzy(User => {:info => "ll"})
|
32
|
-
result.should have(1).user
|
33
|
-
result.first.should == user2
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
it '02' do
|
38
|
-
User.create(:info => "cool")
|
39
|
-
User.create(:info => "hello")
|
40
|
-
|
41
|
-
result = User.fuzzy(User => {:info => "olo"})
|
42
|
-
result.should have(0).user
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
it '03' do
|
47
|
-
User.create(:info => "cool")
|
48
|
-
User.create(:info => "hello")
|
49
|
-
|
50
|
-
result = User.fuzzy(User => {:info => "l"})
|
51
|
-
|
52
|
-
User.all.should have(2).user
|
53
|
-
result.should have(2).user
|
54
|
-
end
|
55
|
-
|
56
|
-
it '04' do
|
57
|
-
user = User.create(:info => "cool")
|
58
|
-
User.create(:info => "hello")
|
59
|
-
user.blogs.create(:title => "yeah")
|
60
|
-
|
61
|
-
result = User.includes(:blogs).fuzzy(User => {:info => "lll"}, Blog => {:title => "y"})
|
62
|
-
|
63
|
-
result.should have(1).user
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
5
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,14 +8,9 @@ require 'rspec/rails'
|
|
8
8
|
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
9
9
|
|
10
10
|
RSpec.configure do |config|
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# config.mock_with :mocha
|
16
|
-
# config.mock_with :flexmock
|
17
|
-
# config.mock_with :rr
|
18
|
-
config.mock_with :rspec
|
11
|
+
|
12
|
+
config.mock_with :rr
|
13
|
+
# config.mock_with :rspec
|
19
14
|
|
20
15
|
config.before(:suite) do
|
21
16
|
DatabaseCleaner.strategy = :transaction
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: induction_cannon_01
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- zhanyinan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-04 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,24 +49,54 @@ dependencies:
|
|
49
49
|
type: :runtime
|
50
50
|
requirement: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
52
|
+
name: jquery-rails
|
53
53
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 25
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
- 2
|
62
|
+
- 7
|
63
|
+
version: 0.2.7
|
64
|
+
prerelease: false
|
65
|
+
type: :runtime
|
66
|
+
requirement: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: inherited_resources
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
prerelease: false
|
79
|
+
type: :runtime
|
80
|
+
requirement: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: dragoon_system
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
54
84
|
none: false
|
55
85
|
requirements:
|
56
86
|
- - "="
|
57
87
|
- !ruby/object:Gem::Version
|
58
|
-
hash:
|
88
|
+
hash: 19
|
59
89
|
segments:
|
60
90
|
- 0
|
61
91
|
- 1
|
62
|
-
-
|
63
|
-
version: 0.1.
|
92
|
+
- 4
|
93
|
+
version: 0.1.4
|
64
94
|
prerelease: false
|
65
95
|
type: :runtime
|
66
|
-
requirement: *
|
96
|
+
requirement: *id005
|
67
97
|
- !ruby/object:Gem::Dependency
|
68
98
|
name: bundler
|
69
|
-
version_requirements: &
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
70
100
|
none: false
|
71
101
|
requirements:
|
72
102
|
- - ~>
|
@@ -79,10 +109,10 @@ dependencies:
|
|
79
109
|
version: 1.0.10
|
80
110
|
prerelease: false
|
81
111
|
type: :development
|
82
|
-
requirement: *
|
112
|
+
requirement: *id006
|
83
113
|
- !ruby/object:Gem::Dependency
|
84
114
|
name: jeweler
|
85
|
-
version_requirements: &
|
115
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
86
116
|
none: false
|
87
117
|
requirements:
|
88
118
|
- - ~>
|
@@ -95,10 +125,10 @@ dependencies:
|
|
95
125
|
version: 1.5.1
|
96
126
|
prerelease: false
|
97
127
|
type: :development
|
98
|
-
requirement: *
|
128
|
+
requirement: *id007
|
99
129
|
- !ruby/object:Gem::Dependency
|
100
130
|
name: rspec-rails
|
101
|
-
version_requirements: &
|
131
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
102
132
|
none: false
|
103
133
|
requirements:
|
104
134
|
- - ~>
|
@@ -111,10 +141,10 @@ dependencies:
|
|
111
141
|
version: 2.5.0
|
112
142
|
prerelease: false
|
113
143
|
type: :development
|
114
|
-
requirement: *
|
144
|
+
requirement: *id008
|
115
145
|
- !ruby/object:Gem::Dependency
|
116
146
|
name: ruby-debug
|
117
|
-
version_requirements: &
|
147
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
118
148
|
none: false
|
119
149
|
requirements:
|
120
150
|
- - ">="
|
@@ -125,7 +155,7 @@ dependencies:
|
|
125
155
|
version: "0"
|
126
156
|
prerelease: false
|
127
157
|
type: :development
|
128
|
-
requirement: *
|
158
|
+
requirement: *id009
|
129
159
|
description: personal suit, base on dragoon_system
|
130
160
|
email: toward7seas@gmail.com
|
131
161
|
executables: []
|
@@ -134,7 +164,6 @@ extensions: []
|
|
134
164
|
|
135
165
|
extra_rdoc_files:
|
136
166
|
- LICENSE.txt
|
137
|
-
- README
|
138
167
|
- README.rdoc
|
139
168
|
files:
|
140
169
|
- .document
|
@@ -142,7 +171,6 @@ files:
|
|
142
171
|
- Gemfile
|
143
172
|
- Gemfile.lock
|
144
173
|
- LICENSE.txt
|
145
|
-
- README
|
146
174
|
- README.rdoc
|
147
175
|
- Rakefile
|
148
176
|
- VERSION
|
@@ -189,7 +217,9 @@ files:
|
|
189
217
|
- induction_cannon_01.gemspec
|
190
218
|
- lib/induction_cannon_01.rb
|
191
219
|
- lib/tasks/.gitkeep
|
220
|
+
- lib/tasks/custom.rake
|
192
221
|
- pkg/induction_cannon_01-0.0.1.gem
|
222
|
+
- pkg/induction_cannon_01-0.0.2.gem
|
193
223
|
- public/404.html
|
194
224
|
- public/422.html
|
195
225
|
- public/500.html
|
@@ -197,15 +227,17 @@ files:
|
|
197
227
|
- public/images/rails.png
|
198
228
|
- public/index.html
|
199
229
|
- public/javascripts/application.js
|
200
|
-
- public/javascripts/
|
201
|
-
- public/javascripts/
|
202
|
-
- public/javascripts/effects.js
|
203
|
-
- public/javascripts/prototype.js
|
230
|
+
- public/javascripts/jquery.js
|
231
|
+
- public/javascripts/jquery.min.js
|
204
232
|
- public/javascripts/rails.js
|
205
233
|
- public/robots.txt
|
206
234
|
- public/stylesheets/.gitkeep
|
207
235
|
- public/stylesheets/scaffold.css
|
208
236
|
- script/rails
|
237
|
+
- spec/controllers/users_controller_spec.rb
|
238
|
+
- spec/factories/user.rb
|
239
|
+
- spec/models/base/search_spec.rb
|
240
|
+
- spec/models/base/transaction_spec.rb
|
209
241
|
- spec/models/extra_spec.rb
|
210
242
|
- spec/models/user_spec.rb
|
211
243
|
- spec/spec_helper.rb
|
@@ -245,6 +277,10 @@ signing_key:
|
|
245
277
|
specification_version: 3
|
246
278
|
summary: personal suit, base on dragoon_system
|
247
279
|
test_files:
|
280
|
+
- spec/controllers/users_controller_spec.rb
|
281
|
+
- spec/factories/user.rb
|
282
|
+
- spec/models/base/search_spec.rb
|
283
|
+
- spec/models/base/transaction_spec.rb
|
248
284
|
- spec/models/extra_spec.rb
|
249
285
|
- spec/models/user_spec.rb
|
250
286
|
- spec/spec_helper.rb
|
data/README
DELETED
@@ -1,256 +0,0 @@
|
|
1
|
-
== Welcome to Rails
|
2
|
-
|
3
|
-
Rails is a web-application framework that includes everything needed to create
|
4
|
-
database-backed web applications according to the Model-View-Control pattern.
|
5
|
-
|
6
|
-
This pattern splits the view (also called the presentation) into "dumb"
|
7
|
-
templates that are primarily responsible for inserting pre-built data in between
|
8
|
-
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
-
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
-
persist themselves to a database. The controller handles the incoming requests
|
11
|
-
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
-
and directing data to the view.
|
13
|
-
|
14
|
-
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
-
layer entitled Active Record. This layer allows you to present the data from
|
16
|
-
database rows as objects and embellish these data objects with business logic
|
17
|
-
methods. You can read more about Active Record in
|
18
|
-
link:files/vendor/rails/activerecord/README.html.
|
19
|
-
|
20
|
-
The controller and view are handled by the Action Pack, which handles both
|
21
|
-
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
-
are bundled in a single package due to their heavy interdependence. This is
|
23
|
-
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
-
more separate. Each of these packages can be used independently outside of
|
25
|
-
Rails. You can read more about Action Pack in
|
26
|
-
link:files/vendor/rails/actionpack/README.html.
|
27
|
-
|
28
|
-
|
29
|
-
== Getting Started
|
30
|
-
|
31
|
-
1. At the command prompt, create a new Rails application:
|
32
|
-
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
-
|
34
|
-
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
-
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
-
|
37
|
-
3. Go to http://localhost:3000/ and you'll see:
|
38
|
-
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
-
|
40
|
-
4. Follow the guidelines to start developing your application. You can find
|
41
|
-
the following resources handy:
|
42
|
-
|
43
|
-
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
-
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
-
|
46
|
-
|
47
|
-
== Debugging Rails
|
48
|
-
|
49
|
-
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
-
will help you debug it and get it back on the rails.
|
51
|
-
|
52
|
-
First area to check is the application log files. Have "tail -f" commands
|
53
|
-
running on the server.log and development.log. Rails will automatically display
|
54
|
-
debugging and runtime information to these files. Debugging info will also be
|
55
|
-
shown in the browser on requests from 127.0.0.1.
|
56
|
-
|
57
|
-
You can also log your own messages directly into the log file from your code
|
58
|
-
using the Ruby logger class from inside your controllers. Example:
|
59
|
-
|
60
|
-
class WeblogController < ActionController::Base
|
61
|
-
def destroy
|
62
|
-
@weblog = Weblog.find(params[:id])
|
63
|
-
@weblog.destroy
|
64
|
-
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
The result will be a message in your log file along the lines of:
|
69
|
-
|
70
|
-
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
-
|
72
|
-
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
-
|
74
|
-
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
-
several books available online as well:
|
76
|
-
|
77
|
-
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
-
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
-
|
80
|
-
These two books will bring you up to speed on the Ruby language and also on
|
81
|
-
programming in general.
|
82
|
-
|
83
|
-
|
84
|
-
== Debugger
|
85
|
-
|
86
|
-
Debugger support is available through the debugger command when you start your
|
87
|
-
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
-
execution at any point in the code, investigate and change the model, and then,
|
89
|
-
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
-
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
-
|
92
|
-
class WeblogController < ActionController::Base
|
93
|
-
def index
|
94
|
-
@posts = Post.find(:all)
|
95
|
-
debugger
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
So the controller will accept the action, run the first line, then present you
|
100
|
-
with a IRB prompt in the server window. Here you can do things like:
|
101
|
-
|
102
|
-
>> @posts.inspect
|
103
|
-
=> "[#<Post:0x14a6be8
|
104
|
-
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
-
#<Post:0x14a6620
|
106
|
-
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
-
>> @posts.first.title = "hello from a debugger"
|
108
|
-
=> "hello from a debugger"
|
109
|
-
|
110
|
-
...and even better, you can examine how your runtime objects actually work:
|
111
|
-
|
112
|
-
>> f = @posts.first
|
113
|
-
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
-
>> f.
|
115
|
-
Display all 152 possibilities? (y or n)
|
116
|
-
|
117
|
-
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
-
|
119
|
-
|
120
|
-
== Console
|
121
|
-
|
122
|
-
The console is a Ruby shell, which allows you to interact with your
|
123
|
-
application's domain model. Here you'll have all parts of the application
|
124
|
-
configured, just like it is when the application is running. You can inspect
|
125
|
-
domain models, change values, and save to the database. Starting the script
|
126
|
-
without arguments will launch it in the development environment.
|
127
|
-
|
128
|
-
To start the console, run <tt>rails console</tt> from the application
|
129
|
-
directory.
|
130
|
-
|
131
|
-
Options:
|
132
|
-
|
133
|
-
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
-
made to the database.
|
135
|
-
* Passing an environment name as an argument will load the corresponding
|
136
|
-
environment. Example: <tt>rails console production</tt>.
|
137
|
-
|
138
|
-
To reload your controllers and models after launching the console run
|
139
|
-
<tt>reload!</tt>
|
140
|
-
|
141
|
-
More information about irb can be found at:
|
142
|
-
link:http://www.rubycentral.com/pickaxe/irb.html
|
143
|
-
|
144
|
-
|
145
|
-
== dbconsole
|
146
|
-
|
147
|
-
You can go to the command line of your database directly through <tt>rails
|
148
|
-
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
-
defined in database.yml. Starting the script without arguments will connect you
|
150
|
-
to the development database. Passing an argument will connect you to a different
|
151
|
-
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
-
PostgreSQL and SQLite 3.
|
153
|
-
|
154
|
-
== Description of Contents
|
155
|
-
|
156
|
-
The default directory structure of a generated Ruby on Rails application:
|
157
|
-
|
158
|
-
|-- app
|
159
|
-
| |-- controllers
|
160
|
-
| |-- helpers
|
161
|
-
| |-- mailers
|
162
|
-
| |-- models
|
163
|
-
| `-- views
|
164
|
-
| `-- layouts
|
165
|
-
|-- config
|
166
|
-
| |-- environments
|
167
|
-
| |-- initializers
|
168
|
-
| `-- locales
|
169
|
-
|-- db
|
170
|
-
|-- doc
|
171
|
-
|-- lib
|
172
|
-
| `-- tasks
|
173
|
-
|-- log
|
174
|
-
|-- public
|
175
|
-
| |-- images
|
176
|
-
| |-- javascripts
|
177
|
-
| `-- stylesheets
|
178
|
-
|-- script
|
179
|
-
|-- test
|
180
|
-
| |-- fixtures
|
181
|
-
| |-- functional
|
182
|
-
| |-- integration
|
183
|
-
| |-- performance
|
184
|
-
| `-- unit
|
185
|
-
|-- tmp
|
186
|
-
| |-- cache
|
187
|
-
| |-- pids
|
188
|
-
| |-- sessions
|
189
|
-
| `-- sockets
|
190
|
-
`-- vendor
|
191
|
-
`-- plugins
|
192
|
-
|
193
|
-
app
|
194
|
-
Holds all the code that's specific to this particular application.
|
195
|
-
|
196
|
-
app/controllers
|
197
|
-
Holds controllers that should be named like weblogs_controller.rb for
|
198
|
-
automated URL mapping. All controllers should descend from
|
199
|
-
ApplicationController which itself descends from ActionController::Base.
|
200
|
-
|
201
|
-
app/models
|
202
|
-
Holds models that should be named like post.rb. Models descend from
|
203
|
-
ActiveRecord::Base by default.
|
204
|
-
|
205
|
-
app/views
|
206
|
-
Holds the template files for the view that should be named like
|
207
|
-
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
208
|
-
eRuby syntax by default.
|
209
|
-
|
210
|
-
app/views/layouts
|
211
|
-
Holds the template files for layouts to be used with views. This models the
|
212
|
-
common header/footer method of wrapping views. In your views, define a layout
|
213
|
-
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
214
|
-
Inside default.html.erb, call <% yield %> to render the view using this
|
215
|
-
layout.
|
216
|
-
|
217
|
-
app/helpers
|
218
|
-
Holds view helpers that should be named like weblogs_helper.rb. These are
|
219
|
-
generated for you automatically when using generators for controllers.
|
220
|
-
Helpers can be used to wrap functionality for your views into methods.
|
221
|
-
|
222
|
-
config
|
223
|
-
Configuration files for the Rails environment, the routing map, the database,
|
224
|
-
and other dependencies.
|
225
|
-
|
226
|
-
db
|
227
|
-
Contains the database schema in schema.rb. db/migrate contains all the
|
228
|
-
sequence of Migrations for your schema.
|
229
|
-
|
230
|
-
doc
|
231
|
-
This directory is where your application documentation will be stored when
|
232
|
-
generated using <tt>rake doc:app</tt>
|
233
|
-
|
234
|
-
lib
|
235
|
-
Application specific libraries. Basically, any kind of custom code that
|
236
|
-
doesn't belong under controllers, models, or helpers. This directory is in
|
237
|
-
the load path.
|
238
|
-
|
239
|
-
public
|
240
|
-
The directory available for the web server. Contains subdirectories for
|
241
|
-
images, stylesheets, and javascripts. Also contains the dispatchers and the
|
242
|
-
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
243
|
-
server.
|
244
|
-
|
245
|
-
script
|
246
|
-
Helper scripts for automation and generation.
|
247
|
-
|
248
|
-
test
|
249
|
-
Unit and functional tests along with fixtures. When using the rails generate
|
250
|
-
command, template test files will be generated for you and placed in this
|
251
|
-
directory.
|
252
|
-
|
253
|
-
vendor
|
254
|
-
External libraries that the application depends on. Also includes the plugins
|
255
|
-
subdirectory. If the app has frozen rails, those gems also go here, under
|
256
|
-
vendor/rails/. This directory is in the load path.
|