bootstrap-datepicker-rails 1.1.1.4 → 1.1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/bootstrap-datepicker-rails.gemspec +1 -1
  4. data/lib/bootstrap-datepicker-rails/version.rb +1 -1
  5. data/vendor/assets/javascripts/bootstrap-datepicker/core.js +56 -32
  6. metadata +2 -57
  7. data/testapp/.gitignore +0 -16
  8. data/testapp/Gemfile +0 -18
  9. data/testapp/README.rdoc +0 -261
  10. data/testapp/Rakefile +0 -7
  11. data/testapp/app/assets/images/rails.png +0 -0
  12. data/testapp/app/assets/javascripts/application.js +0 -17
  13. data/testapp/app/assets/javascripts/home.js.coffee +0 -3
  14. data/testapp/app/assets/stylesheets/application.css +0 -14
  15. data/testapp/app/assets/stylesheets/boots.scss +0 -1
  16. data/testapp/app/controllers/application_controller.rb +0 -3
  17. data/testapp/app/controllers/home_controller.rb +0 -4
  18. data/testapp/app/helpers/application_helper.rb +0 -2
  19. data/testapp/app/helpers/home_helper.rb +0 -2
  20. data/testapp/app/mailers/.gitkeep +0 -0
  21. data/testapp/app/models/.gitkeep +0 -0
  22. data/testapp/app/views/home/index.html.erb +0 -27
  23. data/testapp/app/views/layouts/application.html.erb +0 -14
  24. data/testapp/config.ru +0 -4
  25. data/testapp/config/application.rb +0 -59
  26. data/testapp/config/boot.rb +0 -6
  27. data/testapp/config/database.yml +0 -25
  28. data/testapp/config/environment.rb +0 -5
  29. data/testapp/config/environments/development.rb +0 -37
  30. data/testapp/config/environments/production.rb +0 -69
  31. data/testapp/config/environments/test.rb +0 -37
  32. data/testapp/config/initializers/backtrace_silencers.rb +0 -7
  33. data/testapp/config/initializers/inflections.rb +0 -15
  34. data/testapp/config/initializers/mime_types.rb +0 -5
  35. data/testapp/config/initializers/secret_token.rb +0 -7
  36. data/testapp/config/initializers/session_store.rb +0 -8
  37. data/testapp/config/initializers/wrap_parameters.rb +0 -14
  38. data/testapp/config/locales/en.yml +0 -5
  39. data/testapp/config/routes.rb +0 -62
  40. data/testapp/db/seeds.rb +0 -7
  41. data/testapp/doc/README_FOR_APP +0 -2
  42. data/testapp/lib/assets/.gitkeep +0 -0
  43. data/testapp/lib/tasks/.gitkeep +0 -0
  44. data/testapp/log/.gitkeep +0 -0
  45. data/testapp/public/404.html +0 -26
  46. data/testapp/public/422.html +0 -26
  47. data/testapp/public/500.html +0 -25
  48. data/testapp/public/favicon.ico +0 -0
  49. data/testapp/public/robots.txt +0 -5
  50. data/testapp/script/rails +0 -6
  51. data/testapp/test/fixtures/.gitkeep +0 -0
  52. data/testapp/test/functional/.gitkeep +0 -0
  53. data/testapp/test/functional/home_controller_test.rb +0 -9
  54. data/testapp/test/integration/.gitkeep +0 -0
  55. data/testapp/test/performance/browsing_test.rb +0 -12
  56. data/testapp/test/test_helper.rb +0 -13
  57. data/testapp/test/unit/.gitkeep +0 -0
  58. data/testapp/test/unit/helpers/home_helper_test.rb +0 -4
  59. data/testapp/vendor/assets/javascripts/.gitkeep +0 -0
  60. data/testapp/vendor/assets/stylesheets/.gitkeep +0 -0
  61. data/testapp/vendor/plugins/.gitkeep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2773a6cc6f29b235e7bb8a338ad90277db221239
4
- data.tar.gz: de98226e02f6ba2fea86a4fb00d7d97814087605
3
+ metadata.gz: f47082c19a2c86f5f95136fa2280c24080a8ac84
4
+ data.tar.gz: 055dbe2d01e492784d32202885b7c90ae90fca07
5
5
  SHA512:
6
- metadata.gz: e152fbdda1ede806aac99fcd3416e624af8c9ca98ae470f7a560f982412be287413ca87d037a5ef2702295dc2834aeaf9a58a11d2c2be65faad67aeda9c64831
7
- data.tar.gz: 4f2b640e6c5840dba9a275dce04fb9ced4cb3b5ba33bb385b368c5fe673739e22f65b5623a1ca712b2e17da5adb808e52e91761caa8bbdefe4976e4372c02ab9
6
+ metadata.gz: f61bb94b3159d4c71369f745a265e2337ddde81f005798e195f4fba3b801cd2880a291c9f4b488760eb4966bb99df89cf19b3e50be49dba394d72583107a6ba9
7
+ data.tar.gz: a485b1ec12a5d3abf939720f832ea0235d286a4cd38c3394812d1252584b25e55db9a0d839e13f919ab0cb663c79726a98fa2db90cf6bc57b0c2ef2058d336e0
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Bootstrap Datepicker for Rails
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/bootstrap-datepicker-rails.png)](http://badge.fury.io/rb/bootstrap-datepicker-rails)
4
+
3
5
  [![endorse](https://api.coderwall.com/nerian/endorsecount.png)](https://coderwall.com/nerian)
4
6
 
5
7
  bootstrap-datepicker-rails project integrates a datepicker with Rails 3 assets pipeline.
@@ -69,7 +71,7 @@ There are a lot of options you can pass to datepicker(). They are documented at
69
71
  Use Github Issues.
70
72
 
71
73
  ## License
72
- Copyright (c) 2011 Gonzalo Rodríguez-Baltanás Díaz
74
+ Copyright (c) 2012-2013 Gonzalo Rodríguez-Baltanás Díaz
73
75
 
74
76
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
75
77
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
 
12
12
  gem.name = "bootstrap-datepicker-rails"
13
13
  gem.require_paths = ["lib"]
14
- gem.files = `git ls-files`.split("\n")
14
+ gem.files = `git ls-files`.split("\n").reject { |i| i=~/testapp/}
15
15
  gem.version = BootstrapDatepickerRails::Rails::VERSION
16
16
 
17
17
  gem.add_dependency "railties", ">= 3.0"
@@ -1,5 +1,5 @@
1
1
  module BootstrapDatepickerRails
2
2
  module Rails
3
- VERSION = "1.1.1.4"
3
+ VERSION = "1.1.1.5"
4
4
  end
5
5
  end
@@ -73,8 +73,8 @@
73
73
 
74
74
  this._allow_update = false;
75
75
 
76
- this.setStartDate(this.o.startDate);
77
- this.setEndDate(this.o.endDate);
76
+ this.setStartDate(this._o.startDate);
77
+ this.setEndDate(this._o.endDate);
78
78
  this.setDaysOfWeekDisabled(this.o.daysOfWeekDisabled);
79
79
 
80
80
  this.fillDow();
@@ -143,14 +143,20 @@
143
143
  var format = DPGlobal.parseFormat(o.format);
144
144
  if (o.startDate !== -Infinity) {
145
145
  if (!!o.startDate) {
146
- o.startDate = DPGlobal.parseDate(o.startDate, format, o.language);
146
+ if (o.startDate instanceof Date)
147
+ o.startDate = this._local_to_utc(this._zero_time(o.startDate));
148
+ else
149
+ o.startDate = DPGlobal.parseDate(o.startDate, format, o.language);
147
150
  } else {
148
151
  o.startDate = -Infinity;
149
152
  }
150
153
  }
151
154
  if (o.endDate !== Infinity) {
152
155
  if (!!o.endDate) {
153
- o.endDate = DPGlobal.parseDate(o.endDate, format, o.language);
156
+ if (o.endDate instanceof Date)
157
+ o.endDate = this._local_to_utc(this._zero_time(o.endDate));
158
+ else
159
+ o.endDate = DPGlobal.parseDate(o.endDate, format, o.language);
154
160
  } else {
155
161
  o.endDate = Infinity;
156
162
  }
@@ -257,9 +263,9 @@
257
263
  // Clicked outside the datepicker, hide it
258
264
  if (!(
259
265
  this.element.is(e.target) ||
260
- this.element.find(e.target).size() ||
266
+ this.element.find(e.target).length ||
261
267
  this.picker.is(e.target) ||
262
- this.picker.find(e.target).size()
268
+ this.picker.find(e.target).length
263
269
  )) {
264
270
  this.hide();
265
271
  }
@@ -283,7 +289,7 @@
283
289
  },
284
290
  _trigger: function(event, altdate){
285
291
  var date = altdate || this.date,
286
- local_date = new Date(date.getTime() + (date.getTimezoneOffset()*60000));
292
+ local_date = this._utc_to_local(date);
287
293
 
288
294
  this.element.trigger({
289
295
  type: event,
@@ -338,9 +344,21 @@
338
344
  }
339
345
  },
340
346
 
347
+ _utc_to_local: function(utc){
348
+ return new Date(utc.getTime() + (utc.getTimezoneOffset()*60000));
349
+ },
350
+ _local_to_utc: function(local){
351
+ return new Date(local.getTime() - (local.getTimezoneOffset()*60000));
352
+ },
353
+ _zero_time: function(local){
354
+ return new Date(local.getFullYear(), local.getMonth(), local.getDate());
355
+ },
356
+ _zero_utc_time: function(utc){
357
+ return new Date(Date.UTC(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate()));
358
+ },
359
+
341
360
  getDate: function() {
342
- var d = this.getUTCDate();
343
- return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
361
+ return this._utc_to_local(this.getUTCDate());
344
362
  },
345
363
 
346
364
  getUTCDate: function() {
@@ -348,7 +366,7 @@
348
366
  },
349
367
 
350
368
  setDate: function(d) {
351
- this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
369
+ this.setUTCDate(this._local_to_utc(d));
352
370
  },
353
371
 
354
372
  setUTCDate: function(d) {
@@ -397,14 +415,15 @@
397
415
  calendarHeight = this.picker.outerHeight(),
398
416
  visualPadding = 10,
399
417
  windowWidth = $window.width(),
400
- windowHeight = $window.height();
418
+ windowHeight = $window.height(),
419
+ scrollTop = $window.scrollTop();
401
420
 
402
421
  var zIndex = parseInt(this.element.parents().filter(function() {
403
422
  return $(this).css('z-index') != 'auto';
404
423
  }).first().css('z-index'))+10;
405
424
  var offset = this.component ? this.component.parent().offset() : this.element.offset();
406
- var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(true);
407
- var width = this.component ? this.component.outerWidth(true) : this.element.outerWidth(true);
425
+ var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(false);
426
+ var width = this.component ? this.component.outerWidth(true) : this.element.outerWidth(false);
408
427
  var left = offset.left,
409
428
  top = offset.top;
410
429
 
@@ -434,8 +453,8 @@
434
453
  var yorient = this.o.orientation.y,
435
454
  top_overflow, bottom_overflow;
436
455
  if (yorient === 'auto') {
437
- top_overflow = 0 + offset.top - calendarHeight;
438
- bottom_overflow = windowHeight - (offset.top + height + calendarHeight);
456
+ top_overflow = -scrollTop + offset.top - calendarHeight;
457
+ bottom_overflow = scrollTop + windowHeight - (offset.top + height + calendarHeight);
439
458
  if (Math.max(top_overflow, bottom_overflow) === bottom_overflow)
440
459
  yorient = 'top';
441
460
  else
@@ -445,7 +464,7 @@
445
464
  if (yorient === 'top')
446
465
  top += height;
447
466
  else
448
- top -= calendarHeight + parseInt(this.picker.css('padding'));
467
+ top -= calendarHeight + parseInt(this.picker.css('padding-top'));
449
468
 
450
469
  this.picker.css({
451
470
  top: top,
@@ -462,7 +481,7 @@
462
481
  if(arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
463
482
  date = arguments[0];
464
483
  if (date instanceof Date)
465
- date = new Date(date.getTime() - (date.getTimezoneOffset()*60000));
484
+ date = this._local_to_utc(date);
466
485
  fromArgs = true;
467
486
  } else {
468
487
  date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val();
@@ -475,10 +494,13 @@
475
494
 
476
495
  if (this.date < this.o.startDate) {
477
496
  this.viewDate = new Date(this.o.startDate);
497
+ this.date = new Date(this.o.startDate);
478
498
  } else if (this.date > this.o.endDate) {
479
499
  this.viewDate = new Date(this.o.endDate);
500
+ this.date = new Date(this.o.endDate);
480
501
  } else {
481
502
  this.viewDate = new Date(this.date);
503
+ this.date = new Date(this.date);
482
504
  }
483
505
  this.fill();
484
506
  },
@@ -602,19 +624,21 @@
602
624
  clsName = this.getClassNames(prevMonth);
603
625
  clsName.push('day');
604
626
 
605
- var before = this.o.beforeShowDay(prevMonth);
606
- if (before === undefined)
607
- before = {};
608
- else if (typeof(before) === 'boolean')
609
- before = {enabled: before};
610
- else if (typeof(before) === 'string')
611
- before = {classes: before};
612
- if (before.enabled === false)
613
- clsName.push('disabled');
614
- if (before.classes)
615
- clsName = clsName.concat(before.classes.split(/\s+/));
616
- if (before.tooltip)
617
- tooltip = before.tooltip;
627
+ if (this.o.beforeShowDay !== $.noop){
628
+ var before = this.o.beforeShowDay(this._utc_to_local(prevMonth));
629
+ if (before === undefined)
630
+ before = {};
631
+ else if (typeof(before) === 'boolean')
632
+ before = {enabled: before};
633
+ else if (typeof(before) === 'string')
634
+ before = {classes: before};
635
+ if (before.enabled === false)
636
+ clsName.push('disabled');
637
+ if (before.classes)
638
+ clsName = clsName.concat(before.classes.split(/\s+/));
639
+ if (before.tooltip)
640
+ tooltip = before.tooltip;
641
+ }
618
642
 
619
643
  clsName = $.unique(clsName);
620
644
  html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + '>'+prevMonth.getUTCDate() + '</td>');
@@ -1295,9 +1319,9 @@
1295
1319
  },
1296
1320
  headTemplate: '<thead>'+
1297
1321
  '<tr>'+
1298
- '<th class="prev"><i class="icon-arrow-left"/></th>'+
1322
+ '<th class="prev">&laquo;</th>'+
1299
1323
  '<th colspan="5" class="datepicker-switch"></th>'+
1300
- '<th class="next"><i class="icon-arrow-right"/></th>'+
1324
+ '<th class="next">&raquo;</th>'+
1301
1325
  '</tr>'+
1302
1326
  '</thead>',
1303
1327
  contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-datepicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1.4
4
+ version: 1.1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gonzalo Rodríguez-Baltanás Díaz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-02 00:00:00.000000000 Z
11
+ date: 2013-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -97,61 +97,6 @@ files:
97
97
  - lib/bootstrap-datepicker-rails/engine.rb
98
98
  - lib/bootstrap-datepicker-rails/railtie.rb
99
99
  - lib/bootstrap-datepicker-rails/version.rb
100
- - testapp/.gitignore
101
- - testapp/Gemfile
102
- - testapp/README.rdoc
103
- - testapp/Rakefile
104
- - testapp/app/assets/images/rails.png
105
- - testapp/app/assets/javascripts/application.js
106
- - testapp/app/assets/javascripts/home.js.coffee
107
- - testapp/app/assets/stylesheets/application.css
108
- - testapp/app/assets/stylesheets/boots.scss
109
- - testapp/app/controllers/application_controller.rb
110
- - testapp/app/controllers/home_controller.rb
111
- - testapp/app/helpers/application_helper.rb
112
- - testapp/app/helpers/home_helper.rb
113
- - testapp/app/mailers/.gitkeep
114
- - testapp/app/models/.gitkeep
115
- - testapp/app/views/home/index.html.erb
116
- - testapp/app/views/layouts/application.html.erb
117
- - testapp/config.ru
118
- - testapp/config/application.rb
119
- - testapp/config/boot.rb
120
- - testapp/config/database.yml
121
- - testapp/config/environment.rb
122
- - testapp/config/environments/development.rb
123
- - testapp/config/environments/production.rb
124
- - testapp/config/environments/test.rb
125
- - testapp/config/initializers/backtrace_silencers.rb
126
- - testapp/config/initializers/inflections.rb
127
- - testapp/config/initializers/mime_types.rb
128
- - testapp/config/initializers/secret_token.rb
129
- - testapp/config/initializers/session_store.rb
130
- - testapp/config/initializers/wrap_parameters.rb
131
- - testapp/config/locales/en.yml
132
- - testapp/config/routes.rb
133
- - testapp/db/seeds.rb
134
- - testapp/doc/README_FOR_APP
135
- - testapp/lib/assets/.gitkeep
136
- - testapp/lib/tasks/.gitkeep
137
- - testapp/log/.gitkeep
138
- - testapp/public/404.html
139
- - testapp/public/422.html
140
- - testapp/public/500.html
141
- - testapp/public/favicon.ico
142
- - testapp/public/robots.txt
143
- - testapp/script/rails
144
- - testapp/test/fixtures/.gitkeep
145
- - testapp/test/functional/.gitkeep
146
- - testapp/test/functional/home_controller_test.rb
147
- - testapp/test/integration/.gitkeep
148
- - testapp/test/performance/browsing_test.rb
149
- - testapp/test/test_helper.rb
150
- - testapp/test/unit/.gitkeep
151
- - testapp/test/unit/helpers/home_helper_test.rb
152
- - testapp/vendor/assets/javascripts/.gitkeep
153
- - testapp/vendor/assets/stylesheets/.gitkeep
154
- - testapp/vendor/plugins/.gitkeep
155
100
  - vendor/assets/javascripts/bootstrap-datepicker/core.js
156
101
  - vendor/assets/javascripts/bootstrap-datepicker/index.js
157
102
  - vendor/assets/javascripts/bootstrap-datepicker/locales/bootstrap-datepicker.ar.js
data/testapp/.gitignore DELETED
@@ -1,16 +0,0 @@
1
- # See http://help.github.com/ignore-files/ for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile ~/.gitignore_global
6
-
7
- # Ignore bundler config
8
- /.bundle
9
-
10
- # Ignore the default SQLite database.
11
- /db/*.sqlite3
12
-
13
- # Ignore all logfiles and tempfiles.
14
- /log/*.log
15
- /tmp
16
- public/assets
data/testapp/Gemfile DELETED
@@ -1,18 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'rails'
4
-
5
- gem 'sqlite3'
6
-
7
- group :assets do
8
- gem 'sass-rails'
9
- gem 'coffee-rails'
10
-
11
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
12
- # gem 'therubyracer', :platform => :ruby
13
-
14
- gem 'uglifier'
15
- gem 'bootstrap-sass'
16
- gem 'bootstrap-datepicker-rails', :path => '../'
17
- gem 'jquery-rails'
18
- end
data/testapp/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.