jquery-raty-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/LICENSE.md +31 -0
  2. data/README.md +60 -0
  3. data/Rakefile +212 -0
  4. data/lib/jquery-raty-rails.rb +4 -0
  5. data/lib/jquery-raty-rails/engine.rb +7 -0
  6. data/lib/jquery-raty-rails/version.rb +3 -0
  7. data/lib/tasks/jquery-raty-rails_tasks.rake +4 -0
  8. data/test/dummy/README.rdoc +261 -0
  9. data/test/dummy/Rakefile +7 -0
  10. data/test/dummy/app/assets/javascripts/application.js +15 -0
  11. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  12. data/test/dummy/app/controllers/application_controller.rb +3 -0
  13. data/test/dummy/app/helpers/application_helper.rb +2 -0
  14. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  15. data/test/dummy/config.ru +4 -0
  16. data/test/dummy/config/application.rb +56 -0
  17. data/test/dummy/config/boot.rb +10 -0
  18. data/test/dummy/config/database.yml +25 -0
  19. data/test/dummy/config/environment.rb +5 -0
  20. data/test/dummy/config/environments/development.rb +37 -0
  21. data/test/dummy/config/environments/production.rb +67 -0
  22. data/test/dummy/config/environments/test.rb +37 -0
  23. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  24. data/test/dummy/config/initializers/inflections.rb +15 -0
  25. data/test/dummy/config/initializers/mime_types.rb +5 -0
  26. data/test/dummy/config/initializers/secret_token.rb +7 -0
  27. data/test/dummy/config/initializers/session_store.rb +8 -0
  28. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  29. data/test/dummy/config/locales/en.yml +5 -0
  30. data/test/dummy/config/routes.rb +58 -0
  31. data/test/dummy/db/test.sqlite3 +0 -0
  32. data/test/dummy/log/test.log +99 -0
  33. data/test/dummy/public/404.html +26 -0
  34. data/test/dummy/public/422.html +26 -0
  35. data/test/dummy/public/500.html +25 -0
  36. data/test/dummy/public/favicon.ico +0 -0
  37. data/test/dummy/script/rails +6 -0
  38. data/test/dummy/tmp/cache/assets/C02/3F0/sprockets%2F619690c308e86239202d2f8384756e91 +0 -0
  39. data/test/dummy/tmp/cache/assets/C3B/AF0/sprockets%2F5ec1e6aff22441566232033268083c00 +0 -0
  40. data/test/dummy/tmp/cache/assets/C70/1E0/sprockets%2Fba085081b43ffb396af0573041665303 +0 -0
  41. data/test/dummy/tmp/cache/assets/CAA/000/sprockets%2F10ef2257116ded54c1510608578f4d9a +0 -0
  42. data/test/dummy/tmp/cache/assets/D12/970/sprockets%2F55a6f6c1f8ee36e41266b2d65a38b308 +0 -0
  43. data/test/dummy/tmp/cache/assets/D12/FA0/sprockets%2Fc5ff28f084f58772221c004a47caa79f +0 -0
  44. data/test/dummy/tmp/cache/assets/D16/320/sprockets%2F5f11731d08f66c5ef4deb4804966b6a4 +0 -0
  45. data/test/dummy/tmp/cache/assets/D17/860/sprockets%2Fb5cf2f2c9e11ca58cf80c14879286057 +0 -0
  46. data/test/dummy/tmp/cache/assets/D35/EC0/sprockets%2F153d022974e52522ecb5bebf9c2b4a57 +0 -0
  47. data/test/dummy/tmp/cache/assets/D3F/5A0/sprockets%2F9c02ba98562a2723d317b5de25df77fa +0 -0
  48. data/test/dummy/tmp/cache/assets/D47/1F0/sprockets%2Fbc622247a7b39fc859f20289a85db6da +0 -0
  49. data/test/dummy/tmp/cache/assets/D53/B70/sprockets%2F67b5e5944c6d15774e8658fec33daed1 +0 -0
  50. data/test/dummy/tmp/cache/assets/D71/070/sprockets%2F4ab558ba0a40a53f86f367ef0875c5df +0 -0
  51. data/test/dummy/tmp/cache/assets/D91/3D0/sprockets%2F584ef87c314c77dbaffc21200eca26b0 +0 -0
  52. data/test/dummy/tmp/cache/assets/DD5/BD0/sprockets%2Fc82ad1f32183cc6c8db9ef9de57ae091 +0 -0
  53. data/test/dummy/tmp/cache/assets/DF5/FC0/sprockets%2Faac096d23f7a9f81113e6afd54fd0eba +0 -0
  54. data/test/integration/jquery_raty_rails_integration_test.rb +27 -0
  55. data/test/test_helper.rb +16 -0
  56. data/vendor/assets/images/jquery.raty/cancel-off.png +0 -0
  57. data/vendor/assets/images/jquery.raty/cancel-on.png +0 -0
  58. data/vendor/assets/images/jquery.raty/star-half.png +0 -0
  59. data/vendor/assets/images/jquery.raty/star-off.png +0 -0
  60. data/vendor/assets/images/jquery.raty/star-on.png +0 -0
  61. data/vendor/assets/javascripts/jquery.raty.js +460 -0
  62. data/vendor/assets/javascripts/jquery.raty.min.js +16 -0
  63. metadata +305 -0
@@ -0,0 +1,31 @@
1
+ *jquery-raty-rails* is released under a **BSD license**, adapted from
2
+ <http://opensource.org/licenses/bsd-license.php>
3
+
4
+ Copyright &copy; 2012 Brian M. Clapper.
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright notice,
14
+ this list of conditions and the following disclaimer in the documentation
15
+ and/or other materials provided with the distribution.
16
+
17
+ * Neither the names "clapper.org", nor the names of the project's contributors
18
+ may be used to endorse or promote products derived from this software
19
+ without specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+ POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,60 @@
1
+ # jquery-raty-rails
2
+
3
+ ## Introduction
4
+
5
+ *jquery-raty-rails* is a Ruby gem that wraps the [jQuery Raty][] plugin,
6
+ allowing its image and Javascript files to be served via the [Rails][]
7
+ [asset pipeline][].
8
+
9
+ [jQuery Raty][] is a useful "star rating" [jQuery][] plugin.
10
+
11
+ **This project is not officially associated with the [jQuery Raty][] project.**
12
+
13
+ ## Installation
14
+
15
+ ### Install the gem
16
+
17
+ *jquery-raty-rails* requires Rails 3, since it depends on the asset pipeline.
18
+
19
+ To install, add one of the following to your Rails project's `Gemfile`:
20
+
21
+ gem 'jquery-raty-rails' # Released version
22
+ gem 'jquery-raty-rails', github: 'bmc/jquery-raty-rails' # Bleeding edge
23
+
24
+ Then, install the gem by running `bundle install`.
25
+
26
+ ### Configure the assets
27
+
28
+ Modify the [Sprockets manifest][] in your `application.js` file to include
29
+ *one* of the following, depending on whether you want to include the compressed
30
+ Javascript or the uncompressed Javascript:
31
+
32
+ //= require jquery.raty
33
+ //= require jquery.raty.min
34
+
35
+ ## Usage
36
+
37
+ At this point, your Rails application has access to jQuery Raty. See the
38
+ [jQuery Raty][] web site for instructions on how to use the plugin.
39
+
40
+ ## Notes
41
+
42
+ * The [jQuery Raty][] images are installed so that their assets paths won't
43
+ conflict with same-named images in the application or in other gems.
44
+ * This [blog post][], by Stephen Ball, was a huge help in figuring out how
45
+ to create this gem.
46
+
47
+ ## Copyrights, License, etc.
48
+
49
+ [jQuery Raty][] is copyright &copy; [Washington Botelho][].
50
+
51
+ *jquery-raty-rails* copyright &copy; 2012 Brian M. Clapper and is released
52
+ under a [BSD license](/bmc/jquery-raty-rails/blob/master/LICENSE.md).
53
+
54
+ [blog post]: http://rakeroutes.com/blog/write-a-gem-for-the-rails-asset-pipeline/
55
+ [Rails]: http://rubyonrails.org/
56
+ [jQuery]: http://jquery.org/
57
+ [jQuery Raty]: http://www.wbotelhos.com/raty/
58
+ [asset pipeline]: http://guides.rubyonrails.org/asset_pipeline.html
59
+ [Sprockets manifest]: https://github.com/sstephenson/sprockets#the-directive-processor
60
+ [Washington Botelho]: https://github.com/wbotelhos
@@ -0,0 +1,212 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'JqueryRatyRails'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+
35
+ task :default => :test
36
+
37
+ # ---------------------------------------------------------------------------
38
+ # Local additions
39
+ # ---------------------------------------------------------------------------
40
+
41
+ require 'fileutils'
42
+ require 'pathname'
43
+
44
+ include FileUtils
45
+
46
+ ROOT = Pathname(File.dirname(__FILE__))
47
+ DOWNLOAD_DIR = ROOT + "tmp/download"
48
+ ASSETS = ROOT + 'vendor/assets'
49
+ PACKAGE = "jquery-raty-rails"
50
+ GEMSPEC = "#{PACKAGE}.gemspec"
51
+
52
+ def load_gem
53
+ eval File.open(GEMSPEC).read
54
+ end
55
+
56
+ def gem_name
57
+ gem = load_gem
58
+ version = gem.version.to_s
59
+ "#{PACKAGE}-#{version}.gem"
60
+ end
61
+
62
+ # Tasks
63
+
64
+ desc "Build the gem"
65
+ task :gem => gem_name
66
+
67
+ desc "Build the gem"
68
+ file gem_name do
69
+ require 'rubygems/builder'
70
+ raise "Gem package not defined" unless defined? Gem
71
+ spec = eval File.open(GEMSPEC).read
72
+ Gem::Builder.new(spec).build
73
+ end
74
+
75
+ desc "Publish the gem"
76
+ task :publish => :gem do
77
+ sh "gem push #{gem_name}"
78
+ end
79
+
80
+ desc "Update to the most recently released version of jQuery Raty"
81
+ task :update => [:download_raty, :copy_raty] do
82
+ rm_rf "tmp"
83
+ end
84
+
85
+ desc "Download and unpack the latest version of jquery-raty"
86
+ task :download_raty do
87
+ require 'octokit'
88
+ require 'time'
89
+
90
+ gh = Octokit::Client.new
91
+ newest_time = 0
92
+ newest = nil
93
+ download = gh.downloads('wbotelhos/raty').select do |dl|
94
+ dl["content_type"] == "application/zip"
95
+ end.map do |dl|
96
+ dl["timestamp"] = Time.iso8601 dl["created_at"]
97
+ dl
98
+ end.sort do |dl1, dl2|
99
+ dl1["timestamp"].to_i <=> dl2["timestamp"].to_i
100
+ end.last
101
+
102
+ raise "Can't find suitable download" if download.nil?
103
+
104
+ rm_rf DOWNLOAD_DIR
105
+ mkdir_p DOWNLOAD_DIR
106
+
107
+ url = download["html_url"]
108
+ uri = URI(url)
109
+ filename = File.basename(uri.path)
110
+ local_path = DOWNLOAD_DIR + filename
111
+
112
+ download(uri, local_path)
113
+ unzip local_path
114
+ end
115
+
116
+ desc "Copy the jquery-raty assets in place"
117
+ task :copy_raty do
118
+ %w[javascripts images/jquery.raty].each do |d|
119
+ mkdir_p ASSETS + d
120
+ end
121
+
122
+ Dir.glob(DOWNLOAD_DIR + 'img/*') do |f|
123
+ cp(f, ASSETS + "images/jquery.raty/")
124
+ end
125
+
126
+ js_file = DOWNLOAD_DIR + 'js/jquery.raty.js'
127
+ puts "Editing and copying #{js_file}"
128
+ js = File.open(js_file).readlines.map do |line|
129
+ case line
130
+ when /^(\s+path\s+:)\s'([^']+)'(.*)$/
131
+ line = "#{$1}'/assets/jquery.raty/'#{$3}\n"
132
+ end
133
+ line.gsub(/\r/, "").gsub(%r{^/\*!}, "/**")
134
+ end
135
+
136
+ full_js = ASSETS + "javascripts/jquery.raty.js"
137
+ File.open(full_js, "wb") { |f| f.write(js.join('')) }
138
+
139
+ min_js = ASSETS + "javascripts/jquery.raty.min.js"
140
+ minify full_js, min_js
141
+ end
142
+
143
+ # Download a URL, handling redirects and SSL.
144
+ #
145
+ # Parameters:
146
+ #
147
+ # uri - URI object
148
+ # dest - destination path
149
+ def download(uri, dest)
150
+ require 'net/http'
151
+
152
+ # Would use open-uri, as shown, but it pukes on the GitHub redirection
153
+ # from an https URL to a cloud http URL.
154
+ #
155
+ # open(local_path, 'wb') do |file|
156
+ # file << open(url).read
157
+ # end
158
+ keep_going = true
159
+ while keep_going
160
+ use_ssl = uri.scheme == 'https'
161
+ Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
162
+ request = Net::HTTP::Get.new uri.request_uri
163
+ puts "Downloading #{uri.to_s}"
164
+ http.request request do |response|
165
+ if response.is_a? Net::HTTPSuccess
166
+ File.open(dest, 'wb') do |f|
167
+ response.read_body do |chunk|
168
+ f.write chunk
169
+ end
170
+ end
171
+ keep_going = false
172
+
173
+ elsif (response.code[0] == '3') && response['location']
174
+ # Redirect.
175
+ puts "(Redirected to #{response['location']}"
176
+ uri = URI(response['location'])
177
+ else
178
+ raise "Download failed: #{response.code} #{response.message}"
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
184
+
185
+ def unzip(path)
186
+ require 'zip/zip'
187
+
188
+ puts "Unpacking #{path}"
189
+ Zip::ZipFile.open(path) do |zip_file|
190
+ zip_file.each do |entry|
191
+ dest = File.join(DOWNLOAD_DIR, entry.name)
192
+ mkdir_p File.dirname(dest), verbose: false
193
+ zip_file.extract(entry, dest)
194
+ end
195
+ end
196
+ end
197
+
198
+ # Minify JS. Currently expects Google Closure to be installed.
199
+ def minify(input_file, output_file)
200
+ #require 'uglifier'
201
+ require 'tempfile'
202
+
203
+ puts "Minifying #{input_file} to #{output_file}."
204
+ Tempfile.open('jquery-raty') do |temp|
205
+ sh 'closure', input_file.to_s, temp.path
206
+ temp.rewind
207
+ File.open(output_file, 'wb') do |out|
208
+ out.puts "/* Minified by Google Closure */"
209
+ out.write(temp.read)
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,4 @@
1
+ require 'jquery-raty-rails/engine'
2
+
3
+ module JqueryRatyRails
4
+ end
@@ -0,0 +1,7 @@
1
+ module JqueryRatyRails
2
+ class Engine < ::Rails::Engine
3
+ initializer 'jquery-raty-rails.load-jquery-raty-rails' do |app|
4
+ app.middleware.use ::ActionDispatch::Static, "#{root}/vendor"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module JqueryRatyRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :jquery-raty-rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,261 @@
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.