rails3-jquery-autocomplete 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/{CHANGELOG.md → CHANGELOG.MD} +1 -0
  2. data/README.markdown +4 -1
  3. data/lib/generators/templates/autocomplete-rails-uncompressed.js +1 -1
  4. data/lib/generators/templates/autocomplete-rails.js +1 -1
  5. data/lib/rails3-jquery-autocomplete.rb +1 -1
  6. data/lib/rails3-jquery-autocomplete/form_helper.rb +1 -0
  7. data/lib/rails3-jquery-autocomplete/formtastic_plugin.rb +3 -4
  8. data/lib/rails3-jquery-autocomplete/version.rb +1 -1
  9. metadata +10 -104
  10. data/.document +0 -5
  11. data/.gitignore +0 -26
  12. data/Gemfile +0 -18
  13. data/integration/.gitignore +0 -2
  14. data/integration/.rspec +0 -1
  15. data/integration/Gemfile +0 -18
  16. data/integration/README +0 -256
  17. data/integration/Rakefile +0 -7
  18. data/integration/app/controllers/application_controller.rb +0 -3
  19. data/integration/app/controllers/autocomplete_controller.rb +0 -7
  20. data/integration/app/controllers/id_elements_controller.rb +0 -8
  21. data/integration/app/controllers/multiple_selections_controller.rb +0 -7
  22. data/integration/app/controllers/nested_models_controller.rb +0 -8
  23. data/integration/app/controllers/scoped_autocompletes_controller.rb +0 -7
  24. data/integration/app/controllers/simple_forms_controller.rb +0 -7
  25. data/integration/app/controllers/sub_classes_controller.rb +0 -7
  26. data/integration/app/helpers/application_helper.rb +0 -2
  27. data/integration/app/helpers/autocomplete_helper.rb +0 -2
  28. data/integration/app/helpers/error_messages_helper.rb +0 -23
  29. data/integration/app/helpers/id_elements_helper.rb +0 -2
  30. data/integration/app/helpers/layout_helper.rb +0 -22
  31. data/integration/app/helpers/sub_classes_helper.rb +0 -2
  32. data/integration/app/models/address.rb +0 -2
  33. data/integration/app/models/brand.rb +0 -18
  34. data/integration/app/models/feature.rb +0 -13
  35. data/integration/app/models/foreign_brand.rb +0 -15
  36. data/integration/app/models/product.rb +0 -17
  37. data/integration/app/views/autocomplete/new.html.haml +0 -10
  38. data/integration/app/views/id_elements/new.html.haml +0 -12
  39. data/integration/app/views/layouts/application.html.haml +0 -21
  40. data/integration/app/views/multiple_selections/new.html.haml +0 -9
  41. data/integration/app/views/nested_models/new.html.haml +0 -11
  42. data/integration/app/views/scoped_autocompletes/new.html.haml +0 -10
  43. data/integration/app/views/simple_forms/new.html.haml +0 -8
  44. data/integration/app/views/sub_classes/new.html.haml +0 -9
  45. data/integration/autotest/discover.rb +0 -2
  46. data/integration/config.ru +0 -4
  47. data/integration/config/application.rb +0 -42
  48. data/integration/config/boot.rb +0 -13
  49. data/integration/config/cucumber.yml +0 -8
  50. data/integration/config/database.yml +0 -25
  51. data/integration/config/environment.rb +0 -5
  52. data/integration/config/environments/development.rb +0 -26
  53. data/integration/config/environments/production.rb +0 -49
  54. data/integration/config/environments/test.rb +0 -35
  55. data/integration/config/initializers/backtrace_silencers.rb +0 -7
  56. data/integration/config/initializers/inflections.rb +0 -10
  57. data/integration/config/initializers/mime_types.rb +0 -5
  58. data/integration/config/initializers/secret_token.rb +0 -7
  59. data/integration/config/initializers/session_store.rb +0 -8
  60. data/integration/config/locales/en.yml +0 -5
  61. data/integration/config/routes.rb +0 -90
  62. data/integration/db/migrate/20101209014338_create_brands.rb +0 -13
  63. data/integration/db/migrate/20101209014355_create_products.rb +0 -14
  64. data/integration/db/migrate/20101209053936_add_type_to_brand.rb +0 -9
  65. data/integration/db/migrate/20110209020136_create_features.rb +0 -14
  66. data/integration/db/migrate/20110423000347_add_state_to_brands.rb +0 -9
  67. data/integration/db/migrate/20110512153732_create_addresses.rb +0 -13
  68. data/integration/db/migrate/20110512153811_add_address_id_to_brand.rb +0 -9
  69. data/integration/db/schema.rb +0 -44
  70. data/integration/db/seeds.rb +0 -3
  71. data/integration/doc/README_FOR_APP +0 -2
  72. data/integration/features/autocomplete.feature +0 -73
  73. data/integration/features/step_definitions/autocomplete_steps.rb +0 -15
  74. data/integration/features/step_definitions/pickle_steps.rb +0 -100
  75. data/integration/features/step_definitions/web_steps.rb +0 -219
  76. data/integration/features/support/env.rb +0 -61
  77. data/integration/features/support/paths.rb +0 -33
  78. data/integration/features/support/pickle.rb +0 -24
  79. data/integration/lib/tasks/cucumber.rake +0 -53
  80. data/integration/public/404.html +0 -26
  81. data/integration/public/422.html +0 -26
  82. data/integration/public/500.html +0 -26
  83. data/integration/public/favicon.ico +0 -0
  84. data/integration/public/images/rails.png +0 -0
  85. data/integration/public/javascripts/application.js +0 -0
  86. data/integration/public/javascripts/autocomplete-rails.js +0 -16
  87. data/integration/public/javascripts/jquery-1.5.1.min.js +0 -17
  88. data/integration/public/javascripts/jquery-ui.min.js +0 -97
  89. data/integration/public/javascripts/jquery.min.js +0 -167
  90. data/integration/public/javascripts/rails.js +0 -137
  91. data/integration/public/robots.txt +0 -5
  92. data/integration/public/stylesheets/application.css +0 -61
  93. data/integration/public/stylesheets/jquery-ui-1.8.2.custom.css +0 -489
  94. data/integration/public/stylesheets/sass/application.sass +0 -66
  95. data/integration/script/cucumber +0 -10
  96. data/integration/script/rails +0 -6
  97. data/integration/spec/acceptance/acceptance_helper.rb +0 -15
  98. data/integration/spec/acceptance/autocomplete_spec.rb +0 -81
  99. data/integration/spec/acceptance/support/helpers.rb +0 -12
  100. data/integration/spec/acceptance/support/paths.rb +0 -33
  101. data/integration/spec/spec_helper.rb +0 -37
  102. data/rails3-jquery-autocomplete.gemspec +0 -31
@@ -1,5 +1,6 @@
1
1
  # Changelog
2
2
 
3
+ * 0.9.1 Fixes issues #96 and #32
3
4
  * 0.9.0 Massive rewrite
4
5
  * 0.8.0 Compressed JS file
5
6
  * 0.7.5 Pull request #46
data/README.markdown CHANGED
@@ -216,7 +216,10 @@ The previous example would fetch the extra attribute slogan and update jQuery('#
216
216
 
217
217
  A javascript event named *railsAutocomplete.select* is fired on the input field when a value is selected from the autocomplete drop down. If you need to do something more complex than update fields with data, you can hook into this event, like so:
218
218
 
219
- $('#my_autocomplete_field').bind('railsAutocomplete.select', function(){ /* Do something here */});
219
+ $('#my_autocomplete_field').bind('railsAutocomplete.select', function(event, data){
220
+ /* Do something here */
221
+ alert(data.item.id);
222
+ });
220
223
 
221
224
  ## Formtastic
222
225
 
@@ -103,7 +103,7 @@ $(document).ready(function(){
103
103
  $(this).unbind('keyup.clearId');
104
104
  }
105
105
  });
106
- $(this).trigger('railsAutocomplete.select');
106
+ $(this).trigger('railsAutocomplete.select', ui);
107
107
 
108
108
  return false;
109
109
  }
@@ -13,4 +13,4 @@
13
13
  * Example:
14
14
  * <input type="text" data-autocomplete="/url/to/autocomplete" data-id-element="#id_field">
15
15
  */
16
- $(document).ready(function(){$("input[data-autocomplete]").railsAutocomplete()}),function(a){var b=null;a.fn.railsAutocomplete=function(){return this.live("focus",function(){this.railsAutoCompleter||(this.railsAutoCompleter=new a.railsAutocomplete(this))})},a.railsAutocomplete=function(a){_e=a,this.init(_e)},a.railsAutocomplete.fn=a.railsAutocomplete.prototype={railsAutocomplete:"0.0.1"},a.railsAutocomplete.fn.extend=a.railsAutocomplete.extend=a.extend,a.railsAutocomplete.fn.extend({init:function(a){function c(a){return b(a).pop().replace(/^\s+/,"")}function b(b){return b.split(a.delimiter)}a.delimiter=$(a).attr("data-delimiter")||null,$(a).autocomplete({source:function(b,d){$.getJSON($(a).attr("data-autocomplete"),{term:c(b.term)},function(){$(arguments[0]).each(function(b,c){var d={};d[c.id]=c,$(a).data(d)}),d.apply(null,arguments)})},search:function(){var a=c(this.value);if(a.length<2)return!1},focus:function(){return!1},select:function(c,d){var f=b(this.value);f.pop(),f.push(d.item.value);if(a.delimiter!=null)f.push(""),this.value=f.join(a.delimiter);else{this.value=f.join(""),$(this).attr("data-id-element")&&$($(this).attr("data-id-element")).val(d.item.id);if($(this).attr("data-update-elements")){var g=$(this).data(d.item.id.toString()),h=$.parseJSON($(this).attr("data-update-elements"));for(var i in h)$(h[i]).val(g[i])}}var j=this.value;$(this).bind("keyup.clearId",function(){$(this).val().trim()!=j.trim()&&($($(this).attr("data-id-element")).val(""),$(this).unbind("keyup.clearId"))}),$(this).trigger("railsAutocomplete.select");return!1}})}})}(jQuery)
16
+ $(document).ready(function(){$("input[data-autocomplete]").railsAutocomplete()}),function(a){var b=null;a.fn.railsAutocomplete=function(){return this.live("focus",function(){this.railsAutoCompleter||(this.railsAutoCompleter=new a.railsAutocomplete(this))})},a.railsAutocomplete=function(a){_e=a,this.init(_e)},a.railsAutocomplete.fn=a.railsAutocomplete.prototype={railsAutocomplete:"0.0.1"},a.railsAutocomplete.fn.extend=a.railsAutocomplete.extend=a.extend,a.railsAutocomplete.fn.extend({init:function(a){function c(a){return b(a).pop().replace(/^\s+/,"")}function b(b){return b.split(a.delimiter)}a.delimiter=$(a).attr("data-delimiter")||null,$(a).autocomplete({source:function(b,d){$.getJSON($(a).attr("data-autocomplete"),{term:c(b.term)},function(){$(arguments[0]).each(function(b,c){var d={};d[c.id]=c,$(a).data(d)}),d.apply(null,arguments)})},search:function(){var a=c(this.value);if(a.length<2)return!1},focus:function(){return!1},select:function(c,d){var f=b(this.value);f.pop(),f.push(d.item.value);if(a.delimiter!=null)f.push(""),this.value=f.join(a.delimiter);else{this.value=f.join(""),$(this).attr("data-id-element")&&$($(this).attr("data-id-element")).val(d.item.id);if($(this).attr("data-update-elements")){var g=$(this).data(d.item.id.toString()),h=$.parseJSON($(this).attr("data-update-elements"));for(var i in h)$(h[i]).val(g[i])}}var j=this.value;$(this).bind("keyup.clearId",function(){$(this).val().trim()!=j.trim()&&($($(this).attr("data-id-element")).val(""),$(this).unbind("keyup.clearId"))}),$(this).trigger("railsAutocomplete.select",d);return!1}})}})}(jQuery)
@@ -15,7 +15,7 @@ end
15
15
  # TODO: Better way to load plugins
16
16
  begin
17
17
  require 'formtastic'
18
- class Formtastic::SemanticFormBuilder < ActionView::Helpers::FormBuilder
18
+ class Formtastic::FormBuilder < ActionView::Helpers::FormBuilder
19
19
  include Rails3JQueryAutocomplete::FormtasticPlugin
20
20
  end
21
21
  rescue LoadError
@@ -34,6 +34,7 @@ module ActionView
34
34
  private
35
35
  def rewrite_autocomplete_option(options)
36
36
  options["data-update-elements"] = JSON.generate(options.delete :update_elements) if options[:update_elements]
37
+ options["data-id-element"] = options.delete :id_element if options[:id_element]
37
38
  options
38
39
  end
39
40
  end
@@ -8,14 +8,13 @@ module Rails3JQueryAutocomplete
8
8
  "See http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html for more information.", caller)
9
9
  end
10
10
 
11
- options[:required] = method_required?(method) unless options.key?(:required)
12
11
  options[:as] ||= "autocompleted_string"
13
12
 
14
13
  html_class = [ options[:as], (options[:required] ? :required : :optional) ]
15
14
  html_class << 'error' if @object && @object.respond_to?(:errors) && !@object.errors[method.to_sym].blank?
16
15
 
17
16
  wrapper_html = options.delete(:wrapper_html) || {}
18
- wrapper_html[:id] ||= generate_html_id(method)
17
+ # wrapper_html[:id] ||= generate_html_id(method)
19
18
  wrapper_html[:class] = (html_class << wrapper_html[:class]).flatten.compact.join(' ')
20
19
 
21
20
  if options[:input_html] && options[:input_html][:id]
@@ -23,8 +22,8 @@ module Rails3JQueryAutocomplete
23
22
  options[:label_html][:for] ||= options[:input_html][:id]
24
23
  end
25
24
 
26
- input_parts = self.class.inline_order.dup
27
- input_parts = input_parts - [:errors, :hints] if options[:as] == :hidden
25
+ # input_parts = self.class.inline_order.dup
26
+ # input_parts = input_parts - [:errors, :hints] if options[:as] == :hidden
28
27
 
29
28
  list_item_content = input_parts.map do |type|
30
29
  send(:"inline_#{type}_for", method, options)
@@ -1,3 +1,3 @@
1
1
  module Rails3JQueryAutocomplete
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails3-jquery-autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 0
10
- version: 0.9.0
9
+ - 1
10
+ version: 0.9.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Padilla
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-07 00:00:00 -05:00
18
+ date: 2011-08-08 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -161,120 +161,26 @@ extensions: []
161
161
  extra_rdoc_files: []
162
162
 
163
163
  files:
164
- - .document
165
- - .gitignore
166
- - CHANGELOG.md
167
- - Gemfile
168
- - LICENSE
169
- - README.markdown
170
- - Rakefile
171
- - integration/.gitignore
172
- - integration/.rspec
173
- - integration/Gemfile
174
- - integration/Gemfile.lock
175
- - integration/README
176
- - integration/Rakefile
177
- - integration/app/controllers/application_controller.rb
178
- - integration/app/controllers/autocomplete_controller.rb
179
- - integration/app/controllers/id_elements_controller.rb
180
- - integration/app/controllers/multiple_selections_controller.rb
181
- - integration/app/controllers/nested_models_controller.rb
182
- - integration/app/controllers/scoped_autocompletes_controller.rb
183
- - integration/app/controllers/simple_forms_controller.rb
184
- - integration/app/controllers/sub_classes_controller.rb
185
- - integration/app/helpers/application_helper.rb
186
- - integration/app/helpers/autocomplete_helper.rb
187
- - integration/app/helpers/error_messages_helper.rb
188
- - integration/app/helpers/id_elements_helper.rb
189
- - integration/app/helpers/layout_helper.rb
190
- - integration/app/helpers/sub_classes_helper.rb
191
- - integration/app/models/address.rb
192
- - integration/app/models/brand.rb
193
- - integration/app/models/feature.rb
194
- - integration/app/models/foreign_brand.rb
195
- - integration/app/models/product.rb
196
- - integration/app/views/autocomplete/new.html.haml
197
- - integration/app/views/id_elements/new.html.haml
198
- - integration/app/views/layouts/application.html.haml
199
- - integration/app/views/multiple_selections/new.html.haml
200
- - integration/app/views/nested_models/new.html.haml
201
- - integration/app/views/scoped_autocompletes/new.html.haml
202
- - integration/app/views/simple_forms/new.html.haml
203
- - integration/app/views/sub_classes/new.html.haml
204
- - integration/autotest/discover.rb
205
- - integration/config.ru
206
- - integration/config/application.rb
207
- - integration/config/boot.rb
208
- - integration/config/cucumber.yml
209
- - integration/config/database.yml
210
- - integration/config/environment.rb
211
- - integration/config/environments/development.rb
212
- - integration/config/environments/production.rb
213
- - integration/config/environments/test.rb
214
- - integration/config/initializers/backtrace_silencers.rb
215
- - integration/config/initializers/inflections.rb
216
- - integration/config/initializers/mime_types.rb
217
- - integration/config/initializers/secret_token.rb
218
- - integration/config/initializers/session_store.rb
219
- - integration/config/locales/en.yml
220
- - integration/config/routes.rb
221
- - integration/db/migrate/20101209014338_create_brands.rb
222
- - integration/db/migrate/20101209014355_create_products.rb
223
- - integration/db/migrate/20101209053936_add_type_to_brand.rb
224
- - integration/db/migrate/20110209020136_create_features.rb
225
- - integration/db/migrate/20110423000347_add_state_to_brands.rb
226
- - integration/db/migrate/20110512153732_create_addresses.rb
227
- - integration/db/migrate/20110512153811_add_address_id_to_brand.rb
228
- - integration/db/schema.rb
229
- - integration/db/seeds.rb
230
- - integration/doc/README_FOR_APP
231
- - integration/features/autocomplete.feature
232
- - integration/features/step_definitions/autocomplete_steps.rb
233
- - integration/features/step_definitions/pickle_steps.rb
234
- - integration/features/step_definitions/web_steps.rb
235
- - integration/features/support/env.rb
236
- - integration/features/support/paths.rb
237
- - integration/features/support/pickle.rb
238
- - integration/lib/tasks/cucumber.rake
239
- - integration/public/404.html
240
- - integration/public/422.html
241
- - integration/public/500.html
242
- - integration/public/favicon.ico
243
- - integration/public/images/rails.png
244
- - integration/public/javascripts/application.js
245
- - integration/public/javascripts/autocomplete-rails.js
246
- - integration/public/javascripts/jquery-1.5.1.min.js
247
- - integration/public/javascripts/jquery-ui.min.js
248
- - integration/public/javascripts/jquery.min.js
249
- - integration/public/javascripts/rails.js
250
- - integration/public/robots.txt
251
- - integration/public/stylesheets/application.css
252
- - integration/public/stylesheets/jquery-ui-1.8.2.custom.css
253
- - integration/public/stylesheets/sass/application.sass
254
- - integration/script/cucumber
255
- - integration/script/rails
256
- - integration/spec/acceptance/acceptance_helper.rb
257
- - integration/spec/acceptance/autocomplete_spec.rb
258
- - integration/spec/acceptance/support/helpers.rb
259
- - integration/spec/acceptance/support/paths.rb
260
- - integration/spec/spec_helper.rb
261
164
  - lib/cucumber/autocomplete.rb
262
165
  - lib/generators/autocomplete/install_generator.rb
263
166
  - lib/generators/autocomplete/uncompressed_generator.rb
264
167
  - lib/generators/templates/autocomplete-rails-uncompressed.js
265
168
  - lib/generators/templates/autocomplete-rails.js
266
- - lib/rails3-jquery-autocomplete.rb
267
169
  - lib/rails3-jquery-autocomplete/autocomplete.rb
268
170
  - lib/rails3-jquery-autocomplete/form_helper.rb
269
171
  - lib/rails3-jquery-autocomplete/formtastic_plugin.rb
270
- - lib/rails3-jquery-autocomplete/orm.rb
271
172
  - lib/rails3-jquery-autocomplete/orm/active_record.rb
272
173
  - lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
273
174
  - lib/rails3-jquery-autocomplete/orm/mongoid.rb
175
+ - lib/rails3-jquery-autocomplete/orm.rb
274
176
  - lib/rails3-jquery-autocomplete/simple_form_plugin.rb
275
177
  - lib/rails3-jquery-autocomplete/version.rb
178
+ - lib/rails3-jquery-autocomplete.rb
276
179
  - lib/steak/autocomplete.rb
277
- - rails3-jquery-autocomplete.gemspec
180
+ - CHANGELOG.MD
181
+ - LICENSE
182
+ - README.markdown
183
+ - Rakefile
278
184
  - test/form_helper_test.rb
279
185
  - test/generators/autocomplete/install_generator_test.rb
280
186
  - test/generators/autocomplete/uncompressed_generator_test.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,26 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- tmp
21
-
22
- ## PROJECT::SPECIFIC
23
- .bundle
24
- .rvmrc
25
- .gemrc
26
- Gemfile.lock
data/Gemfile DELETED
@@ -1,18 +0,0 @@
1
- #A sample Gemfile
2
- #source :gemcutter
3
-
4
- #gem 'rails', '~>3.0.0'
5
- #gem 'sqlite3-ruby'
6
- #gem 'jeweler'
7
- #gem 'reek'
8
- #gem 'mongoid', '>= 2.0.0.beta.17'
9
- #gem 'formtastic'
10
-
11
- #group :test do
12
- #gem 'shoulda', '2.11.1'
13
- #gem 'redgreen'
14
- #end
15
- #
16
- source "http://rubygems.org"
17
-
18
- gemspec
@@ -1,2 +0,0 @@
1
- **.sqlite3
2
- log
data/integration/.rspec DELETED
@@ -1 +0,0 @@
1
- --colour
data/integration/Gemfile DELETED
@@ -1,18 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'rails', '~>3.0.3'
4
-
5
- gem 'annotate'
6
- gem 'capybara', '~>0.4.0'
7
- gem 'cucumber-rails', '~>0.3.2'
8
- gem 'rspec-rails'
9
- gem 'steak'
10
- gem 'database_cleaner'
11
- gem 'haml-rails'
12
- gem 'jquery-rails'
13
- gem 'launchy'
14
- gem 'nifty-generators'
15
- gem 'pickle'
16
- gem 'rails3-jquery-autocomplete', :path => '../'
17
- gem 'simple_form'
18
- gem 'sqlite3-ruby', :require => 'sqlite3'
data/integration/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.