netzke-basepack 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +17 -0
- data/README.rdoc +1 -1
- data/Rakefile +3 -0
- data/TODO.rdoc +1 -4
- data/features/form_panel.feature +2 -1
- data/features/grid_panel.feature +134 -5
- data/features/nested_attributes.feature +4 -1
- data/features/paging_form_panel.feature +41 -0
- data/features/search_in_grid.feature +20 -7
- data/features/step_definitions/form_panel_steps.rb +35 -0
- data/features/step_definitions/generic_steps.rb +20 -1
- data/features/step_definitions/grid_panel_steps.rb +63 -0
- data/features/support/env.rb +4 -0
- data/features/validations_in_grid.feature +13 -0
- data/features/virtual_attributes.feature +5 -9
- data/javascripts/basepack.js +21 -650
- data/javascripts/datetimefield.js +24 -0
- data/lib/generators/netzke/basepack_generator.rb +10 -0
- data/{generators/netzke_basepack/templates/public_assets → lib/generators/netzke/templates/assets}/ts-checkbox.gif +0 -0
- data/{generators/netzke_basepack → lib/generators/netzke}/templates/create_netzke_field_lists.rb +0 -0
- data/lib/netzke-basepack.rb +3 -41
- data/lib/netzke/active_record/attributes.rb +17 -21
- data/lib/netzke/basepack.rb +6 -1
- data/lib/netzke/basepack/data_accessor.rb +166 -0
- data/lib/netzke/basepack/form_panel.rb +69 -20
- data/lib/netzke/basepack/form_panel/fields.rb +15 -17
- data/lib/netzke/basepack/form_panel/javascripts/comma_list_cbg.js +7 -0
- data/lib/netzke/basepack/form_panel/javascripts/display_mode.js +6 -0
- data/lib/netzke/basepack/form_panel/javascripts/{main.js → form_panel.js} +42 -8
- data/lib/netzke/basepack/form_panel/javascripts/n_radio_group.js +24 -7
- data/lib/netzke/basepack/form_panel/javascripts/readonly_mode.js +52 -0
- data/lib/netzke/basepack/form_panel/services.rb +28 -2
- data/lib/netzke/basepack/form_panel/stylesheets/readonly_mode.css +14 -0
- data/lib/netzke/basepack/grid_panel.rb +151 -181
- data/lib/netzke/basepack/grid_panel/columns.rb +122 -84
- data/lib/netzke/basepack/grid_panel/javascripts/advanced_search.js +22 -27
- data/lib/netzke/basepack/grid_panel/javascripts/{main.js → grid_panel.js} +182 -108
- data/lib/netzke/basepack/grid_panel/record_form_window.rb +7 -2
- data/lib/netzke/basepack/grid_panel/services.rb +58 -39
- data/lib/netzke/basepack/paging_form_panel.rb +86 -25
- data/lib/netzke/basepack/query_builder.rb +105 -0
- data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +140 -0
- data/lib/netzke/basepack/search_panel.rb +61 -44
- data/lib/netzke/basepack/search_panel/javascripts/condition_field.js +153 -0
- data/lib/netzke/basepack/search_panel/javascripts/search_panel.js +64 -0
- data/lib/netzke/basepack/search_window.rb +64 -0
- data/lib/netzke/basepack/simple_app.rb +1 -1
- data/lib/netzke/basepack/simple_app/javascripts/{main.js → simple_app.js} +0 -0
- data/lib/netzke/basepack/tab_panel.rb +1 -2
- data/lib/netzke/basepack/tab_panel/javascripts/{main.js → tab_panel.js} +0 -0
- data/lib/netzke/basepack/version.rb +1 -1
- data/locales/en.yml +71 -4
- data/netzke-basepack.gemspec +47 -22
- data/spec/active_record/attributes_spec.rb +6 -6
- data/spec/components/form_panel_spec.rb +2 -13
- data/stylesheets/datetimefield.css +54 -0
- data/test/rails_app/Gemfile +3 -3
- data/test/rails_app/Gemfile.lock +67 -57
- data/test/rails_app/README +1 -256
- data/test/rails_app/app/components/book_form.rb +1 -3
- data/test/rails_app/app/components/book_form_with_custom_fields.rb +20 -0
- data/test/rails_app/app/components/book_form_with_nested_attributes.rb +18 -0
- data/test/rails_app/app/components/book_grid.rb +3 -1
- data/test/rails_app/app/components/book_grid_loader.rb +24 -0
- data/test/rails_app/app/components/book_grid_with_custom_columns.rb +28 -0
- data/test/rails_app/app/components/book_grid_with_default_values.rb +1 -1
- data/test/rails_app/app/components/book_grid_with_virtual_attributes.rb +0 -1
- data/test/rails_app/app/components/book_paging_form_panel.rb +3 -2
- data/test/rails_app/app/components/book_presentation.rb +3 -3
- data/test/rails_app/app/components/book_query_builder.rb +8 -0
- data/test/rails_app/app/components/book_search_panel.rb +5 -0
- data/test/rails_app/app/components/book_search_panel/javascripts/i18n_de.js +6 -0
- data/test/rails_app/app/components/double_book_grid.rb +18 -0
- data/test/rails_app/app/components/form_without_model.rb +1 -1
- data/test/rails_app/app/components/paging_form_with_search.rb +39 -0
- data/test/rails_app/app/components/user_grid.rb +1 -1
- data/test/rails_app/app/models/author.rb +1 -0
- data/test/rails_app/config/application.rb +6 -1
- data/test/rails_app/config/database.yml +7 -5
- data/test/rails_app/config/environments/test.rb +1 -1
- data/test/rails_app/config/locales/de.yml +35 -0
- data/test/rails_app/config/locales/es.yml +84 -8
- data/test/rails_app/db/migrate/20101026190021_create_books.rb +2 -2
- data/test/rails_app/db/migrate/20110213213050_create_netzke_component_states.rb +20 -0
- data/test/rails_app/db/schema.rb +2 -18
- data/test/rails_app/public/netzke/basepack/ts-checkbox.gif +0 -0
- data/test/unit/active_record_basepack_test.rb +1 -1
- metadata +46 -45
- data/generators/netzke_basepack/netzke_basepack_generator.rb +0 -13
- data/lib/netzke/basepack/grid_panel/search_window.rb +0 -56
- data/lib/netzke/data_accessor.rb +0 -113
- data/lib/netzke/ext.rb +0 -7
- data/lib/netzke/fields_configurator.rb +0 -170
- data/lib/netzke/json_array_editor.rb +0 -67
- data/lib/netzke/masquerade_selector.rb +0 -53
- data/test/rails_app/app/components/some_search_panel.rb +0 -34
- data/test/rails_app/db/development_structure.sql +0 -93
- data/test/rails_app/db/migrate/20100905214933_create_netzke_preferences.rb +0 -16
@@ -16,8 +16,8 @@ describe Netzke::Basepack::FormPanel do
|
|
16
16
|
form = Netzke::Basepack::FormPanel.new(:model => 'User', :items => [:first_name, :created_at, :role__name])
|
17
17
|
|
18
18
|
form.fields[:first_name][:xtype].should == :textfield
|
19
|
-
form.fields[:created_at][:xtype].should == :
|
20
|
-
form.fields[:role__name][:xtype].should == :
|
19
|
+
form.fields[:created_at][:xtype].should == :datetimefield
|
20
|
+
form.fields[:role__name][:xtype].should == :netzkeremotecombo
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should set correct default field labels" do
|
@@ -28,17 +28,6 @@ describe Netzke::Basepack::FormPanel do
|
|
28
28
|
form.fields[:role__name][:field_label].should == "Role name"
|
29
29
|
end
|
30
30
|
|
31
|
-
it "should set correct field values" do
|
32
|
-
role = Factory(:role, :name => "warrior")
|
33
|
-
user = Factory(:user, :first_name => "Carlos", :last_name => "Castaneda", :role => role)
|
34
|
-
|
35
|
-
form = Netzke::Basepack::FormPanel.new(:model => 'User', :record => user, :items => [:first_name, :last_name, :role__name])
|
36
|
-
|
37
|
-
form.fields[:first_name][:value].should == "Carlos"
|
38
|
-
form.fields[:last_name][:value].should == "Castaneda"
|
39
|
-
form.fields[:role__name][:value].should == "warrior"
|
40
|
-
end
|
41
|
-
|
42
31
|
it "should add primary key field automatically when omitted" do
|
43
32
|
form = Netzke::Basepack::FormPanel.new(:model => 'User', :items => [:first_name, :last_name, :role__name])
|
44
33
|
form.fields[:id].should_not be_nil
|
@@ -0,0 +1,54 @@
|
|
1
|
+
.ux-base-time-picker {
|
2
|
+
}
|
3
|
+
|
4
|
+
.ux-base-time-picker .x-panel-body {
|
5
|
+
padding: 5px;
|
6
|
+
}
|
7
|
+
.ux-date-time-picker {
|
8
|
+
border: 1px solid #1B376C;
|
9
|
+
overflow: hidden;
|
10
|
+
}
|
11
|
+
|
12
|
+
.x-menu .ux-date-time-picker {
|
13
|
+
border-color: #A3BAD9;
|
14
|
+
}
|
15
|
+
|
16
|
+
.x-menu-plain .ux-date-time-picker {
|
17
|
+
border: none;
|
18
|
+
}
|
19
|
+
|
20
|
+
.ux-date-time-picker-inner {
|
21
|
+
position: relative;
|
22
|
+
}
|
23
|
+
|
24
|
+
.ux-date-time-picker .x-date-picker {
|
25
|
+
border: none !important;
|
26
|
+
}
|
27
|
+
|
28
|
+
.ux-date-time-picker-value-ct {
|
29
|
+
border: none;
|
30
|
+
}
|
31
|
+
|
32
|
+
.ux-date-time-picker-value-ct-value-wrap {
|
33
|
+
white-space: nowrap;
|
34
|
+
font: 12px arial, tahoma, verdana, helvetica;
|
35
|
+
}
|
36
|
+
|
37
|
+
.ux-date-time-picker-value-ct-value-label {
|
38
|
+
font-weight: normal;
|
39
|
+
}
|
40
|
+
|
41
|
+
.ux-date-time-picker-value-ct-value {
|
42
|
+
font-weight: bold;
|
43
|
+
cursor: pointer;
|
44
|
+
}
|
45
|
+
|
46
|
+
/* menu */
|
47
|
+
|
48
|
+
.ext-ie .x-date-time-menu {
|
49
|
+
height: 229px;
|
50
|
+
}
|
51
|
+
|
52
|
+
.ext-strict .ext-ie7 .x-date-time-menu {
|
53
|
+
height: 225px;
|
54
|
+
}
|
data/test/rails_app/Gemfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails', '3.0.
|
3
|
+
gem 'rails', '3.0.4'
|
4
4
|
|
5
|
-
gem 'netzke-core'
|
6
|
-
gem 'netzke-persistence'
|
5
|
+
gem 'netzke-core', :path => File.expand_path('../vendor/gems/netzke-core', __FILE__)
|
6
|
+
gem 'netzke-persistence', :path => File.expand_path('../vendor/gems/netzke-persistence', __FILE__)
|
7
7
|
|
8
8
|
gem 'will_paginate', '3.0.pre2'
|
9
9
|
gem 'meta_where'
|
data/test/rails_app/Gemfile.lock
CHANGED
@@ -1,37 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: vendor/gems/netzke-core
|
3
|
+
specs:
|
4
|
+
netzke-core (0.6.6)
|
5
|
+
activesupport (>= 3.0.1)
|
6
|
+
|
7
|
+
PATH
|
8
|
+
remote: vendor/gems/netzke-persistence
|
9
|
+
specs:
|
10
|
+
netzke-persistence (0.1.1)
|
11
|
+
|
1
12
|
GEM
|
2
13
|
remote: http://rubygems.org/
|
3
14
|
specs:
|
4
15
|
abstract (1.0.0)
|
5
|
-
actionmailer (3.0.
|
6
|
-
actionpack (= 3.0.
|
7
|
-
mail (~> 2.2.
|
8
|
-
actionpack (3.0.
|
9
|
-
activemodel (= 3.0.
|
10
|
-
activesupport (= 3.0.
|
16
|
+
actionmailer (3.0.4)
|
17
|
+
actionpack (= 3.0.4)
|
18
|
+
mail (~> 2.2.15)
|
19
|
+
actionpack (3.0.4)
|
20
|
+
activemodel (= 3.0.4)
|
21
|
+
activesupport (= 3.0.4)
|
11
22
|
builder (~> 2.1.2)
|
12
23
|
erubis (~> 2.6.6)
|
13
24
|
i18n (~> 0.4)
|
14
25
|
rack (~> 1.2.1)
|
15
26
|
rack-mount (~> 0.6.13)
|
16
|
-
rack-test (~> 0.5.
|
27
|
+
rack-test (~> 0.5.7)
|
17
28
|
tzinfo (~> 0.3.23)
|
18
|
-
activemodel (3.0.
|
19
|
-
activesupport (= 3.0.
|
29
|
+
activemodel (3.0.4)
|
30
|
+
activesupport (= 3.0.4)
|
20
31
|
builder (~> 2.1.2)
|
21
32
|
i18n (~> 0.4)
|
22
|
-
activerecord (3.0.
|
23
|
-
activemodel (= 3.0.
|
24
|
-
activesupport (= 3.0.
|
33
|
+
activerecord (3.0.4)
|
34
|
+
activemodel (= 3.0.4)
|
35
|
+
activesupport (= 3.0.4)
|
25
36
|
arel (~> 2.0.2)
|
26
37
|
tzinfo (~> 0.3.23)
|
27
|
-
activeresource (3.0.
|
28
|
-
activemodel (= 3.0.
|
29
|
-
activesupport (= 3.0.
|
30
|
-
activesupport (3.0.
|
38
|
+
activeresource (3.0.4)
|
39
|
+
activemodel (= 3.0.4)
|
40
|
+
activesupport (= 3.0.4)
|
41
|
+
activesupport (3.0.4)
|
31
42
|
acts_as_list (0.1.2)
|
32
|
-
arel (2.0.
|
43
|
+
arel (2.0.8)
|
33
44
|
builder (2.1.2)
|
34
|
-
capybara (0.4.
|
45
|
+
capybara (0.4.1.2)
|
35
46
|
celerity (>= 0.7.9)
|
36
47
|
culerity (>= 0.2.4)
|
37
48
|
mime-types (>= 1.16)
|
@@ -39,9 +50,9 @@ GEM
|
|
39
50
|
rack (>= 1.0.0)
|
40
51
|
rack-test (>= 0.5.4)
|
41
52
|
selenium-webdriver (>= 0.0.27)
|
42
|
-
xpath (~> 0.1.
|
43
|
-
celerity (0.8.
|
44
|
-
childprocess (0.1.
|
53
|
+
xpath (~> 0.1.3)
|
54
|
+
celerity (0.8.8)
|
55
|
+
childprocess (0.1.7)
|
45
56
|
ffi (~> 0.6.3)
|
46
57
|
configuration (1.2.0)
|
47
58
|
cucumber (0.10.0)
|
@@ -52,8 +63,8 @@ GEM
|
|
52
63
|
term-ansicolor (~> 1.0.5)
|
53
64
|
cucumber-rails (0.3.2)
|
54
65
|
cucumber (>= 0.8.0)
|
55
|
-
culerity (0.2.
|
56
|
-
database_cleaner (0.6.
|
66
|
+
culerity (0.2.15)
|
67
|
+
database_cleaner (0.6.4)
|
57
68
|
diff-lcs (1.1.2)
|
58
69
|
erubis (2.6.6)
|
59
70
|
abstract (>= 1.0.0)
|
@@ -64,24 +75,21 @@ GEM
|
|
64
75
|
json (~> 1.4.6)
|
65
76
|
i18n (0.5.0)
|
66
77
|
json (1.4.6)
|
67
|
-
json_pure (1.
|
78
|
+
json_pure (1.5.1)
|
68
79
|
launchy (0.3.7)
|
69
80
|
configuration (>= 0.0.5)
|
70
81
|
rake (>= 0.8.1)
|
71
|
-
mail (2.2.
|
82
|
+
mail (2.2.15)
|
72
83
|
activesupport (>= 2.3.6)
|
73
84
|
i18n (>= 0.4.0)
|
74
85
|
mime-types (~> 1.16)
|
75
86
|
treetop (~> 1.4.8)
|
76
|
-
meta_where (0.
|
77
|
-
activerecord (~> 3.0.
|
78
|
-
activesupport (~> 3.0.
|
79
|
-
arel (~> 2.0.
|
87
|
+
meta_where (1.0.3)
|
88
|
+
activerecord (~> 3.0.4)
|
89
|
+
activesupport (~> 3.0.4)
|
90
|
+
arel (~> 2.0.8)
|
80
91
|
mime-types (1.16)
|
81
92
|
mysql2 (0.2.6)
|
82
|
-
netzke-core (0.6.5)
|
83
|
-
activesupport (>= 3.0.1)
|
84
|
-
netzke-persistence (0.1.1)
|
85
93
|
nokogiri (1.4.4)
|
86
94
|
pickle (0.4.4)
|
87
95
|
cucumber (>= 0.8)
|
@@ -94,46 +102,48 @@ GEM
|
|
94
102
|
rack (>= 1.0.0)
|
95
103
|
rack-test (0.5.7)
|
96
104
|
rack (>= 1.0)
|
97
|
-
rails (3.0.
|
98
|
-
actionmailer (= 3.0.
|
99
|
-
actionpack (= 3.0.
|
100
|
-
activerecord (= 3.0.
|
101
|
-
activeresource (= 3.0.
|
102
|
-
activesupport (= 3.0.
|
105
|
+
rails (3.0.4)
|
106
|
+
actionmailer (= 3.0.4)
|
107
|
+
actionpack (= 3.0.4)
|
108
|
+
activerecord (= 3.0.4)
|
109
|
+
activeresource (= 3.0.4)
|
110
|
+
activesupport (= 3.0.4)
|
103
111
|
bundler (~> 1.0)
|
104
|
-
railties (= 3.0.
|
105
|
-
railties (3.0.
|
106
|
-
actionpack (= 3.0.
|
107
|
-
activesupport (= 3.0.
|
112
|
+
railties (= 3.0.4)
|
113
|
+
railties (3.0.4)
|
114
|
+
actionpack (= 3.0.4)
|
115
|
+
activesupport (= 3.0.4)
|
108
116
|
rake (>= 0.8.7)
|
109
117
|
thor (~> 0.14.4)
|
110
118
|
rake (0.8.7)
|
111
|
-
rspec (2.
|
112
|
-
rspec-core (~> 2.
|
113
|
-
rspec-expectations (~> 2.
|
114
|
-
rspec-mocks (~> 2.
|
115
|
-
rspec-core (2.
|
116
|
-
rspec-expectations (2.
|
119
|
+
rspec (2.5.0)
|
120
|
+
rspec-core (~> 2.5.0)
|
121
|
+
rspec-expectations (~> 2.5.0)
|
122
|
+
rspec-mocks (~> 2.5.0)
|
123
|
+
rspec-core (2.5.1)
|
124
|
+
rspec-expectations (2.5.0)
|
117
125
|
diff-lcs (~> 1.1.2)
|
118
|
-
rspec-mocks (2.
|
119
|
-
rspec-rails (2.
|
126
|
+
rspec-mocks (2.5.0)
|
127
|
+
rspec-rails (2.5.0)
|
120
128
|
actionpack (~> 3.0)
|
121
129
|
activesupport (~> 3.0)
|
122
130
|
railties (~> 3.0)
|
123
|
-
rspec (~> 2.
|
131
|
+
rspec (~> 2.5.0)
|
124
132
|
rubyzip (0.9.4)
|
125
|
-
selenium-webdriver (0.1.
|
133
|
+
selenium-webdriver (0.1.3)
|
126
134
|
childprocess (~> 0.1.5)
|
127
135
|
ffi (~> 0.6.3)
|
128
136
|
json_pure
|
129
137
|
rubyzip
|
130
138
|
spork (0.8.4)
|
131
|
-
sqlite3
|
139
|
+
sqlite3 (1.3.3)
|
140
|
+
sqlite3-ruby (1.3.3)
|
141
|
+
sqlite3 (>= 1.3.3)
|
132
142
|
term-ansicolor (1.0.5)
|
133
143
|
thor (0.14.6)
|
134
144
|
treetop (1.4.9)
|
135
145
|
polyglot (>= 0.3.1)
|
136
|
-
tzinfo (0.3.
|
146
|
+
tzinfo (0.3.24)
|
137
147
|
will_paginate (3.0.pre2)
|
138
148
|
xpath (0.1.3)
|
139
149
|
nokogiri (~> 1.3)
|
@@ -152,10 +162,10 @@ DEPENDENCIES
|
|
152
162
|
launchy
|
153
163
|
meta_where
|
154
164
|
mysql2
|
155
|
-
netzke-core
|
156
|
-
netzke-persistence
|
165
|
+
netzke-core!
|
166
|
+
netzke-persistence!
|
157
167
|
pickle
|
158
|
-
rails (= 3.0.
|
168
|
+
rails (= 3.0.4)
|
159
169
|
rspec-rails
|
160
170
|
spork
|
161
171
|
sqlite3-ruby
|
data/test/rails_app/README
CHANGED
@@ -1,256 +1 @@
|
|
1
|
-
|
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
|
-
| |-- models
|
162
|
-
| `-- views
|
163
|
-
| `-- layouts
|
164
|
-
|-- config
|
165
|
-
| |-- environments
|
166
|
-
| |-- initializers
|
167
|
-
| `-- locales
|
168
|
-
|-- db
|
169
|
-
|-- doc
|
170
|
-
|-- lib
|
171
|
-
| `-- tasks
|
172
|
-
|-- log
|
173
|
-
|-- public
|
174
|
-
| |-- images
|
175
|
-
| |-- javascripts
|
176
|
-
| `-- stylesheets
|
177
|
-
|-- script
|
178
|
-
| `-- performance
|
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.
|
1
|
+
Testing app for netzke-basepack
|