jail 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -4
- data/app/models/jail/cdnjs.rb +22 -5
- data/app/models/jail/github.rb +2 -1
- data/app/views/jail/cdnjs/show.html.erb +14 -7
- data/lib/jail/version.rb +1 -1
- metadata +39 -127
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -59
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/jail.rb +0 -4
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/jail.inmates.yml +0 -4
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -4
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -42628
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/dummy/tmp/cache/assets/C78/2D0/sprockets%2F049c9453e2d03a13463ad15568c8521f +0 -0
- data/test/dummy/tmp/cache/assets/CBE/8B0/sprockets%2F45f037820eca943af359e247967580cf +0 -0
- data/test/dummy/tmp/cache/assets/CFA/570/sprockets%2Ffe84858b375458bd418cb85c8f84803c +0 -0
- data/test/dummy/tmp/cache/assets/D15/AE0/sprockets%2F3fd1b8f0c577d6bd951f40857132eb74 +0 -0
- data/test/dummy/tmp/cache/assets/D29/F40/sprockets%2F15ce02e64710b4fa1d3a21f6270fdc74 +0 -0
- data/test/dummy/tmp/cache/assets/D34/BF0/sprockets%2F18a1d0fec1cd74447e07b02d058a289d +0 -0
- data/test/dummy/tmp/cache/assets/D46/B30/sprockets%2F36e940335f9fc2de06c6d8aad556d822 +0 -0
- data/test/dummy/tmp/cache/assets/D4B/BC0/sprockets%2Fa3a0b270a0bb2747cad33e424662fba2 +0 -0
- data/test/dummy/tmp/cache/assets/D76/A70/sprockets%2F360c75fdc8ed695061e3b08da593d7cc +0 -0
- data/test/dummy/tmp/cache/assets/D81/500/sprockets%2F23e9c52aedd634ee57e66663cffa1868 +0 -0
- data/test/dummy/tmp/cache/assets/D9E/630/sprockets%2F0efe12c5dc1902e8cf8f6844b7bca812 +0 -0
- data/test/dummy/tmp/cache/assets/DDF/C90/sprockets%2Fc4dff5559e7f91debdf5da74921c028e +0 -0
- data/test/dummy/tmp/cache/assets/E64/6F0/sprockets%2F8f0e4dd1aa8c3ddea851bf771dce8f8c +0 -0
- data/test/dummy/tmp/pids/server.pid +0 -1
- data/test/dummy/vendor/assets/images/chosen-sprite.png +0 -0
- data/test/dummy/vendor/assets/javascripts/chosen.jquery.js +0 -952
- data/test/dummy/vendor/assets/stylesheets/chosen.css +0 -392
- data/test/fixtures/jqplug/jqgithubs.yml +0 -11
- data/test/functional/jqplug/githubs_controller_test.rb +0 -51
- data/test/functional/jqplug/jqgithubs_controller_test.rb +0 -51
- data/test/integration/navigation_test.rb +0 -10
- data/test/jqplug_test.rb +0 -7
- data/test/test_helper.rb +0 -15
- data/test/unit/helpers/jqplug/githubs_helper_test.rb +0 -6
- data/test/unit/helpers/jqplug/jqgithubs_helper_test.rb +0 -6
- data/test/unit/jqplug/jqgithub_test.rb +0 -9
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Meet Jail : it puts all your Javascripts (& cie) in Rails, with just a click!
|
|
13
13
|
|
14
14
|
config/routes.rb
|
15
15
|
|
16
|
-
mount Jail::Engine => "/jail"
|
16
|
+
mount Jail::Engine => "/jail" if Rails.env.development?
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
@@ -66,17 +66,24 @@ Other approaches where :
|
|
66
66
|
|
67
67
|
## TODO
|
68
68
|
|
69
|
-
- Pjax for
|
69
|
+
- Pjax for loading plugin
|
70
70
|
- plugin installed? (check file existence)
|
71
71
|
- plugin outdated? (overkill ?)
|
72
72
|
- bin/jail
|
73
73
|
|
74
74
|
## Changelog
|
75
75
|
|
76
|
-
|
76
|
+
### 0.2.0
|
77
|
+
- Cdnjs now shows **subfolder content**
|
78
|
+
- fixed bug trying to download a folder
|
79
|
+
- (fix) creates non existing path before downloading
|
80
|
+
|
81
|
+
### 0.1.1
|
82
|
+
- CDNJS Integration + Some Github Refactoring
|
77
83
|
|
78
84
|
## Thanks to
|
79
85
|
|
80
86
|
- [Walter Davis](/walterdavis) for suggesting the awesome idea of including the cdnjs library.
|
81
87
|
|
82
|
-
This project rocks and uses MIT-LICENSE.
|
88
|
+
This project rocks and uses MIT-LICENSE.
|
89
|
+
|
data/app/models/jail/cdnjs.rb
CHANGED
@@ -44,12 +44,29 @@ module Jail
|
|
44
44
|
Pathname(root_path).join(version)
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
@
|
47
|
+
def version_files
|
48
|
+
@version_files ||= github.where(version_path).contents
|
49
49
|
end
|
50
50
|
|
51
|
-
|
52
|
-
|
51
|
+
# build a depth first tree
|
52
|
+
def tree
|
53
|
+
@tree and return @tree
|
54
|
+
@tree = []
|
55
|
+
file_set = version_files
|
56
|
+
|
57
|
+
while child = file_set.shift
|
58
|
+
tree << child #if child.dir?
|
59
|
+
|
60
|
+
if child.type == "dir"
|
61
|
+
file_set.unshift( github.where(child.path).contents ).flatten!
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
@tree
|
66
|
+
end
|
67
|
+
|
68
|
+
def file(path)
|
69
|
+
github.where(path)
|
53
70
|
end
|
54
71
|
|
55
72
|
def mapped_files
|
@@ -57,7 +74,7 @@ module Jail
|
|
57
74
|
end
|
58
75
|
|
59
76
|
def install(params)
|
60
|
-
files_to_write = params.map {|file,
|
77
|
+
files_to_write = params.map {|file, checkbox_val| file if checkbox_val == "1"}.compact
|
61
78
|
|
62
79
|
files_to_write.each do |name|
|
63
80
|
file(name).download()
|
data/app/models/jail/github.rb
CHANGED
@@ -10,17 +10,24 @@
|
|
10
10
|
<%= form_tag "/jail/cdnjs/#{@cdnjs.name}" do %>
|
11
11
|
<fieldset>
|
12
12
|
<legend>Files To Install (uncheck unnecesseray)</legend>
|
13
|
-
<%- @cdnjs.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
<%- @cdnjs.tree.each do |file| %>
|
14
|
+
<%- if file.type == "dir" %>
|
15
|
+
<h3><%= file.name %></h3>
|
16
|
+
<% end %>
|
17
|
+
<%- if file.type == "file" %>
|
18
|
+
<p>
|
19
|
+
<%= label_tag file.name %>
|
20
|
+
<%= check_box('files', file.path, {:checked => true}, checked_value="1", unchecked_value="0") %>
|
21
|
+
</p>
|
22
|
+
<% end %>
|
18
23
|
<% end %>
|
19
24
|
<%= submit_tag "Install" %>
|
20
25
|
</fieldset>
|
21
26
|
<% end %>
|
22
27
|
|
23
28
|
<p>homepage: <%= link_to @cdnjs.homepage, @cdnjs.homepage %></p>
|
24
|
-
<%- @cdnjs.repositories.
|
25
|
-
|
29
|
+
<%- unless @cdnjs.repositories.blank? %>
|
30
|
+
<%- @cdnjs.repositories.map(&:url).each do |url| %>
|
31
|
+
<p>repository : <%= link_to url, url %></p>
|
32
|
+
<% end %>
|
26
33
|
<% end %>
|
data/lib/jail/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Charles Sistovaris
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-10-
|
18
|
+
date: 2012-10-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|
@@ -25,12 +25,11 @@ dependencies:
|
|
25
25
|
requirements:
|
26
26
|
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
28
|
+
hash: 5
|
29
29
|
segments:
|
30
30
|
- 3
|
31
|
-
-
|
32
|
-
|
33
|
-
version: 3.2.8
|
31
|
+
- 1
|
32
|
+
version: "3.1"
|
34
33
|
type: :runtime
|
35
34
|
version_requirements: *id001
|
36
35
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +47,7 @@ dependencies:
|
|
48
47
|
type: :runtime
|
49
48
|
version_requirements: *id002
|
50
49
|
- !ruby/object:Gem::Dependency
|
51
|
-
name: rspec
|
50
|
+
name: rspec-rails
|
52
51
|
prerelease: false
|
53
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
53
|
none: false
|
@@ -89,6 +88,34 @@ dependencies:
|
|
89
88
|
version: "0"
|
90
89
|
type: :development
|
91
90
|
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: webmock
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :development
|
104
|
+
version_requirements: *id006
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: vcr
|
107
|
+
prerelease: false
|
108
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
type: :development
|
118
|
+
version_requirements: *id007
|
92
119
|
description: "\n Developers facility to install or remove jQuery plugins hosted on github by \n adding proper javascripts, stylesheets and images in vendor/assets.\n "
|
93
120
|
email:
|
94
121
|
- charlysisto@gmail.com
|
@@ -121,64 +148,6 @@ files:
|
|
121
148
|
- MIT-LICENSE
|
122
149
|
- Rakefile
|
123
150
|
- README.md
|
124
|
-
- test/dummy/app/assets/javascripts/application.js
|
125
|
-
- test/dummy/app/assets/stylesheets/application.css
|
126
|
-
- test/dummy/app/controllers/application_controller.rb
|
127
|
-
- test/dummy/app/helpers/application_helper.rb
|
128
|
-
- test/dummy/app/views/layouts/application.html.erb
|
129
|
-
- test/dummy/config/application.rb
|
130
|
-
- test/dummy/config/boot.rb
|
131
|
-
- test/dummy/config/database.yml
|
132
|
-
- test/dummy/config/environment.rb
|
133
|
-
- test/dummy/config/environments/development.rb
|
134
|
-
- test/dummy/config/environments/production.rb
|
135
|
-
- test/dummy/config/environments/test.rb
|
136
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
137
|
-
- test/dummy/config/initializers/inflections.rb
|
138
|
-
- test/dummy/config/initializers/jail.rb
|
139
|
-
- test/dummy/config/initializers/mime_types.rb
|
140
|
-
- test/dummy/config/initializers/secret_token.rb
|
141
|
-
- test/dummy/config/initializers/session_store.rb
|
142
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
143
|
-
- test/dummy/config/jail.inmates.yml
|
144
|
-
- test/dummy/config/locales/en.yml
|
145
|
-
- test/dummy/config/routes.rb
|
146
|
-
- test/dummy/config.ru
|
147
|
-
- test/dummy/db/development.sqlite3
|
148
|
-
- test/dummy/log/development.log
|
149
|
-
- test/dummy/public/404.html
|
150
|
-
- test/dummy/public/422.html
|
151
|
-
- test/dummy/public/500.html
|
152
|
-
- test/dummy/public/favicon.ico
|
153
|
-
- test/dummy/Rakefile
|
154
|
-
- test/dummy/README.rdoc
|
155
|
-
- test/dummy/script/rails
|
156
|
-
- test/dummy/tmp/cache/assets/C78/2D0/sprockets%2F049c9453e2d03a13463ad15568c8521f
|
157
|
-
- test/dummy/tmp/cache/assets/CBE/8B0/sprockets%2F45f037820eca943af359e247967580cf
|
158
|
-
- test/dummy/tmp/cache/assets/CFA/570/sprockets%2Ffe84858b375458bd418cb85c8f84803c
|
159
|
-
- test/dummy/tmp/cache/assets/D15/AE0/sprockets%2F3fd1b8f0c577d6bd951f40857132eb74
|
160
|
-
- test/dummy/tmp/cache/assets/D29/F40/sprockets%2F15ce02e64710b4fa1d3a21f6270fdc74
|
161
|
-
- test/dummy/tmp/cache/assets/D34/BF0/sprockets%2F18a1d0fec1cd74447e07b02d058a289d
|
162
|
-
- test/dummy/tmp/cache/assets/D46/B30/sprockets%2F36e940335f9fc2de06c6d8aad556d822
|
163
|
-
- test/dummy/tmp/cache/assets/D4B/BC0/sprockets%2Fa3a0b270a0bb2747cad33e424662fba2
|
164
|
-
- test/dummy/tmp/cache/assets/D76/A70/sprockets%2F360c75fdc8ed695061e3b08da593d7cc
|
165
|
-
- test/dummy/tmp/cache/assets/D81/500/sprockets%2F23e9c52aedd634ee57e66663cffa1868
|
166
|
-
- test/dummy/tmp/cache/assets/D9E/630/sprockets%2F0efe12c5dc1902e8cf8f6844b7bca812
|
167
|
-
- test/dummy/tmp/cache/assets/DDF/C90/sprockets%2Fc4dff5559e7f91debdf5da74921c028e
|
168
|
-
- test/dummy/tmp/cache/assets/E64/6F0/sprockets%2F8f0e4dd1aa8c3ddea851bf771dce8f8c
|
169
|
-
- test/dummy/tmp/pids/server.pid
|
170
|
-
- test/dummy/vendor/assets/images/chosen-sprite.png
|
171
|
-
- test/dummy/vendor/assets/javascripts/chosen.jquery.js
|
172
|
-
- test/dummy/vendor/assets/stylesheets/chosen.css
|
173
|
-
- test/fixtures/jqplug/jqgithubs.yml
|
174
|
-
- test/functional/jqplug/githubs_controller_test.rb
|
175
|
-
- test/functional/jqplug/jqgithubs_controller_test.rb
|
176
|
-
- test/integration/navigation_test.rb
|
177
|
-
- test/jqplug_test.rb
|
178
|
-
- test/test_helper.rb
|
179
|
-
- test/unit/helpers/jqplug/githubs_helper_test.rb
|
180
|
-
- test/unit/helpers/jqplug/jqgithubs_helper_test.rb
|
181
|
-
- test/unit/jqplug/jqgithub_test.rb
|
182
151
|
homepage: https://github.com/charly/jail
|
183
152
|
licenses: []
|
184
153
|
|
@@ -212,63 +181,6 @@ rubygems_version: 1.8.24
|
|
212
181
|
signing_key:
|
213
182
|
specification_version: 3
|
214
183
|
summary: Puts your assets in rails
|
215
|
-
test_files:
|
216
|
-
|
217
|
-
- test/dummy/app/assets/stylesheets/application.css
|
218
|
-
- test/dummy/app/controllers/application_controller.rb
|
219
|
-
- test/dummy/app/helpers/application_helper.rb
|
220
|
-
- test/dummy/app/views/layouts/application.html.erb
|
221
|
-
- test/dummy/config/application.rb
|
222
|
-
- test/dummy/config/boot.rb
|
223
|
-
- test/dummy/config/database.yml
|
224
|
-
- test/dummy/config/environment.rb
|
225
|
-
- test/dummy/config/environments/development.rb
|
226
|
-
- test/dummy/config/environments/production.rb
|
227
|
-
- test/dummy/config/environments/test.rb
|
228
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
229
|
-
- test/dummy/config/initializers/inflections.rb
|
230
|
-
- test/dummy/config/initializers/jail.rb
|
231
|
-
- test/dummy/config/initializers/mime_types.rb
|
232
|
-
- test/dummy/config/initializers/secret_token.rb
|
233
|
-
- test/dummy/config/initializers/session_store.rb
|
234
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
235
|
-
- test/dummy/config/jail.inmates.yml
|
236
|
-
- test/dummy/config/locales/en.yml
|
237
|
-
- test/dummy/config/routes.rb
|
238
|
-
- test/dummy/config.ru
|
239
|
-
- test/dummy/db/development.sqlite3
|
240
|
-
- test/dummy/log/development.log
|
241
|
-
- test/dummy/public/404.html
|
242
|
-
- test/dummy/public/422.html
|
243
|
-
- test/dummy/public/500.html
|
244
|
-
- test/dummy/public/favicon.ico
|
245
|
-
- test/dummy/Rakefile
|
246
|
-
- test/dummy/README.rdoc
|
247
|
-
- test/dummy/script/rails
|
248
|
-
- test/dummy/tmp/cache/assets/C78/2D0/sprockets%2F049c9453e2d03a13463ad15568c8521f
|
249
|
-
- test/dummy/tmp/cache/assets/CBE/8B0/sprockets%2F45f037820eca943af359e247967580cf
|
250
|
-
- test/dummy/tmp/cache/assets/CFA/570/sprockets%2Ffe84858b375458bd418cb85c8f84803c
|
251
|
-
- test/dummy/tmp/cache/assets/D15/AE0/sprockets%2F3fd1b8f0c577d6bd951f40857132eb74
|
252
|
-
- test/dummy/tmp/cache/assets/D29/F40/sprockets%2F15ce02e64710b4fa1d3a21f6270fdc74
|
253
|
-
- test/dummy/tmp/cache/assets/D34/BF0/sprockets%2F18a1d0fec1cd74447e07b02d058a289d
|
254
|
-
- test/dummy/tmp/cache/assets/D46/B30/sprockets%2F36e940335f9fc2de06c6d8aad556d822
|
255
|
-
- test/dummy/tmp/cache/assets/D4B/BC0/sprockets%2Fa3a0b270a0bb2747cad33e424662fba2
|
256
|
-
- test/dummy/tmp/cache/assets/D76/A70/sprockets%2F360c75fdc8ed695061e3b08da593d7cc
|
257
|
-
- test/dummy/tmp/cache/assets/D81/500/sprockets%2F23e9c52aedd634ee57e66663cffa1868
|
258
|
-
- test/dummy/tmp/cache/assets/D9E/630/sprockets%2F0efe12c5dc1902e8cf8f6844b7bca812
|
259
|
-
- test/dummy/tmp/cache/assets/DDF/C90/sprockets%2Fc4dff5559e7f91debdf5da74921c028e
|
260
|
-
- test/dummy/tmp/cache/assets/E64/6F0/sprockets%2F8f0e4dd1aa8c3ddea851bf771dce8f8c
|
261
|
-
- test/dummy/tmp/pids/server.pid
|
262
|
-
- test/dummy/vendor/assets/images/chosen-sprite.png
|
263
|
-
- test/dummy/vendor/assets/javascripts/chosen.jquery.js
|
264
|
-
- test/dummy/vendor/assets/stylesheets/chosen.css
|
265
|
-
- test/fixtures/jqplug/jqgithubs.yml
|
266
|
-
- test/functional/jqplug/githubs_controller_test.rb
|
267
|
-
- test/functional/jqplug/jqgithubs_controller_test.rb
|
268
|
-
- test/integration/navigation_test.rb
|
269
|
-
- test/jqplug_test.rb
|
270
|
-
- test/test_helper.rb
|
271
|
-
- test/unit/helpers/jqplug/githubs_helper_test.rb
|
272
|
-
- test/unit/helpers/jqplug/jqgithubs_helper_test.rb
|
273
|
-
- test/unit/jqplug/jqgithub_test.rb
|
184
|
+
test_files: []
|
185
|
+
|
274
186
|
has_rdoc:
|
data/test/dummy/README.rdoc
DELETED
@@ -1,261 +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.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.org/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
|
-
| |-- assets
|
160
|
-
| |-- images
|
161
|
-
| |-- javascripts
|
162
|
-
| `-- stylesheets
|
163
|
-
| |-- controllers
|
164
|
-
| |-- helpers
|
165
|
-
| |-- mailers
|
166
|
-
| |-- models
|
167
|
-
| `-- views
|
168
|
-
| `-- layouts
|
169
|
-
|-- config
|
170
|
-
| |-- environments
|
171
|
-
| |-- initializers
|
172
|
-
| `-- locales
|
173
|
-
|-- db
|
174
|
-
|-- doc
|
175
|
-
|-- lib
|
176
|
-
| `-- tasks
|
177
|
-
|-- log
|
178
|
-
|-- public
|
179
|
-
|-- script
|
180
|
-
|-- test
|
181
|
-
| |-- fixtures
|
182
|
-
| |-- functional
|
183
|
-
| |-- integration
|
184
|
-
| |-- performance
|
185
|
-
| `-- unit
|
186
|
-
|-- tmp
|
187
|
-
| |-- cache
|
188
|
-
| |-- pids
|
189
|
-
| |-- sessions
|
190
|
-
| `-- sockets
|
191
|
-
`-- vendor
|
192
|
-
|-- assets
|
193
|
-
`-- stylesheets
|
194
|
-
`-- plugins
|
195
|
-
|
196
|
-
app
|
197
|
-
Holds all the code that's specific to this particular application.
|
198
|
-
|
199
|
-
app/assets
|
200
|
-
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
-
|
202
|
-
app/controllers
|
203
|
-
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
-
automated URL mapping. All controllers should descend from
|
205
|
-
ApplicationController which itself descends from ActionController::Base.
|
206
|
-
|
207
|
-
app/models
|
208
|
-
Holds models that should be named like post.rb. Models descend from
|
209
|
-
ActiveRecord::Base by default.
|
210
|
-
|
211
|
-
app/views
|
212
|
-
Holds the template files for the view that should be named like
|
213
|
-
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
-
eRuby syntax by default.
|
215
|
-
|
216
|
-
app/views/layouts
|
217
|
-
Holds the template files for layouts to be used with views. This models the
|
218
|
-
common header/footer method of wrapping views. In your views, define a layout
|
219
|
-
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
-
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
-
layout.
|
222
|
-
|
223
|
-
app/helpers
|
224
|
-
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
-
generated for you automatically when using generators for controllers.
|
226
|
-
Helpers can be used to wrap functionality for your views into methods.
|
227
|
-
|
228
|
-
config
|
229
|
-
Configuration files for the Rails environment, the routing map, the database,
|
230
|
-
and other dependencies.
|
231
|
-
|
232
|
-
db
|
233
|
-
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
-
sequence of Migrations for your schema.
|
235
|
-
|
236
|
-
doc
|
237
|
-
This directory is where your application documentation will be stored when
|
238
|
-
generated using <tt>rake doc:app</tt>
|
239
|
-
|
240
|
-
lib
|
241
|
-
Application specific libraries. Basically, any kind of custom code that
|
242
|
-
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
-
the load path.
|
244
|
-
|
245
|
-
public
|
246
|
-
The directory available for the web server. Also contains the dispatchers and the
|
247
|
-
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
-
server.
|
249
|
-
|
250
|
-
script
|
251
|
-
Helper scripts for automation and generation.
|
252
|
-
|
253
|
-
test
|
254
|
-
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
-
command, template test files will be generated for you and placed in this
|
256
|
-
directory.
|
257
|
-
|
258
|
-
vendor
|
259
|
-
External libraries that the application depends on. Also includes the plugins
|
260
|
-
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
-
vendor/rails/. This directory is in the load path.
|