vinted-raty 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.md +31 -0
- data/README.md +59 -0
- data/Rakefile +212 -0
- data/lib/tasks/vinted-raty_tasks.rake +4 -0
- data/lib/vinted-raty.rb +4 -0
- data/lib/vinted-raty/engine.rb +7 -0
- data/lib/vinted-raty/version.rb +3 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/vinted_raty_integration_test.rb +27 -0
- data/test/test_helper.rb +16 -0
- data/vendor/assets/images/jquery.raty/cancel-off.png +0 -0
- data/vendor/assets/images/jquery.raty/cancel-on.png +0 -0
- data/vendor/assets/images/jquery.raty/star-half.png +0 -0
- data/vendor/assets/images/jquery.raty/star-off.png +0 -0
- data/vendor/assets/images/jquery.raty/star-on.png +0 -0
- data/vendor/assets/javascripts/jquery.raty.js +474 -0
- data/vendor/assets/javascripts/jquery.raty.min.js +12 -0
- metadata +243 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e2cd38610195cb14d274cec43f998edb6a6b23f
|
4
|
+
data.tar.gz: e348b51fd865f2da37c131ec0e758197b898b3e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed2a163c0b4dbe8af4d921203c1e6b88f33c45f042d3fcb4b336efd503cb2e797c6561975561fdb925fa26f8db46ff688ee367c88f3c01f4a2de77a40eeb4ed6
|
7
|
+
data.tar.gz: 46dae494f73a665d49dbe6adb227f7f269d745a8c93bf7ee7f467ba108ab75cb1190fc2e7a329b498d1f1170d1951e7050a0d04e92c2b12d0479220012c78607
|
data/LICENSE.md
ADDED
@@ -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 © 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.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# vinted-raty
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
*vinted-raty* 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
|
+
*vinted-raty* 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 'vinted-raty' # Released version
|
22
|
+
|
23
|
+
Then, install the gem by running `bundle install`.
|
24
|
+
|
25
|
+
### Configure the assets
|
26
|
+
|
27
|
+
Modify the [Sprockets manifest][] in your `application.js` file to include
|
28
|
+
*one* of the following, depending on whether you want to include the compressed
|
29
|
+
Javascript or the uncompressed Javascript:
|
30
|
+
|
31
|
+
//= require jquery.raty
|
32
|
+
//= require jquery.raty.min
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
At this point, your Rails application has access to jQuery Raty. See the
|
37
|
+
[jQuery Raty][] web site for instructions on how to use the plugin.
|
38
|
+
|
39
|
+
## Notes
|
40
|
+
|
41
|
+
* The [jQuery Raty][] images are installed so that their assets paths won't
|
42
|
+
conflict with same-named images in the application or in other gems.
|
43
|
+
* This [blog post][], by Stephen Ball, was a huge help in figuring out how
|
44
|
+
to create this gem.
|
45
|
+
|
46
|
+
## Copyrights, License, etc.
|
47
|
+
|
48
|
+
[jQuery Raty][] is copyright © [Washington Botelho][].
|
49
|
+
|
50
|
+
*vinted-raty* copyright © 2012 Brian M. Clapper and is released
|
51
|
+
under a [BSD license](/bmc/vinted-raty/blob/master/LICENSE.md).
|
52
|
+
|
53
|
+
[blog post]: http://rakeroutes.com/blog/write-a-gem-for-the-rails-asset-pipeline/
|
54
|
+
[Rails]: http://rubyonrails.org/
|
55
|
+
[jQuery]: http://jquery.org/
|
56
|
+
[jQuery Raty]: http://www.wbotelhos.com/raty/
|
57
|
+
[asset pipeline]: http://guides.rubyonrails.org/asset_pipeline.html
|
58
|
+
[Sprockets manifest]: https://github.com/sstephenson/sprockets#the-directive-processor
|
59
|
+
[Washington Botelho]: https://github.com/wbotelhos
|
data/Rakefile
ADDED
@@ -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 = "vinted-raty"
|
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
|
data/lib/vinted-raty.rb
ADDED
@@ -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.
|