go-picasa-go 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +135 -0
- data/Rakefile +16 -0
- data/TODO +10 -0
- data/VERSION +1 -0
- data/bin/go-picasa-go +64 -0
- data/examples/rails-example/README +243 -0
- data/examples/rails-example/Rakefile +10 -0
- data/examples/rails-example/app/controllers/albums_controller.rb +62 -0
- data/examples/rails-example/app/controllers/application_controller.rb +10 -0
- data/examples/rails-example/app/controllers/photos_controller.rb +77 -0
- data/examples/rails-example/app/helpers/albums_helper.rb +9 -0
- data/examples/rails-example/app/helpers/application_helper.rb +3 -0
- data/examples/rails-example/app/models/my_user.rb +9 -0
- data/examples/rails-example/app/views/albums/_form.html.erb +15 -0
- data/examples/rails-example/app/views/albums/edit.html.erb +10 -0
- data/examples/rails-example/app/views/albums/index.html.erb +50 -0
- data/examples/rails-example/app/views/albums/new.html.erb +10 -0
- data/examples/rails-example/app/views/photos/index.html.erb +30 -0
- data/examples/rails-example/app/views/photos/new.html.erb +8 -0
- data/examples/rails-example/app/views/photos/show.html.erb +19 -0
- data/examples/rails-example/config/boot.rb +110 -0
- data/examples/rails-example/config/database.yml +22 -0
- data/examples/rails-example/config/environment.rb +42 -0
- data/examples/rails-example/config/environments/development.rb +17 -0
- data/examples/rails-example/config/environments/production.rb +28 -0
- data/examples/rails-example/config/environments/test.rb +28 -0
- data/examples/rails-example/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails-example/config/initializers/inflections.rb +10 -0
- data/examples/rails-example/config/initializers/mime_types.rb +5 -0
- data/examples/rails-example/config/initializers/new_rails_defaults.rb +21 -0
- data/examples/rails-example/config/initializers/session_store.rb +15 -0
- data/examples/rails-example/config/locales/en.yml +5 -0
- data/examples/rails-example/config/routes.rb +49 -0
- data/examples/rails-example/db/seeds.rb +7 -0
- data/examples/rails-example/doc/README_FOR_APP +2 -0
- data/examples/rails-example/log/development.log +6923 -0
- data/examples/rails-example/log/production.log +0 -0
- data/examples/rails-example/log/server.log +0 -0
- data/examples/rails-example/log/test.log +0 -0
- data/examples/rails-example/public/404.html +30 -0
- data/examples/rails-example/public/422.html +30 -0
- data/examples/rails-example/public/500.html +30 -0
- data/examples/rails-example/public/favicon.ico +0 -0
- data/examples/rails-example/public/images/rails.png +0 -0
- data/examples/rails-example/public/index.html +275 -0
- data/examples/rails-example/public/javascripts/application.js +2 -0
- data/examples/rails-example/public/javascripts/controls.js +963 -0
- data/examples/rails-example/public/javascripts/dragdrop.js +973 -0
- data/examples/rails-example/public/javascripts/effects.js +1128 -0
- data/examples/rails-example/public/javascripts/prototype.js +4320 -0
- data/examples/rails-example/public/robots.txt +5 -0
- data/examples/rails-example/script/about +4 -0
- data/examples/rails-example/script/console +3 -0
- data/examples/rails-example/script/dbconsole +3 -0
- data/examples/rails-example/script/destroy +3 -0
- data/examples/rails-example/script/generate +3 -0
- data/examples/rails-example/script/performance/benchmarker +3 -0
- data/examples/rails-example/script/performance/profiler +3 -0
- data/examples/rails-example/script/plugin +3 -0
- data/examples/rails-example/script/runner +3 -0
- data/examples/rails-example/script/server +3 -0
- data/examples/rails-example/test/functional/albums_controller_test.rb +8 -0
- data/examples/rails-example/test/performance/browsing_test.rb +9 -0
- data/examples/rails-example/test/test_helper.rb +38 -0
- data/examples/rails-example/test/unit/helpers/albums_helper_test.rb +4 -0
- data/go_picasa_go.gemspec +184 -0
- data/init.rb +1 -0
- data/lib/generators/authentication_token_generator.rb +12 -0
- data/lib/generators/template/user_class.erb +9 -0
- data/lib/generators/user_class_generator.rb +50 -0
- data/lib/go_picasa_go.rb +26 -0
- data/lib/patchs/object.rb +21 -0
- data/lib/patchs/ssl.rb +9 -0
- data/lib/picasa/album.rb +267 -0
- data/lib/picasa/authentication.rb +19 -0
- data/lib/picasa/default_album.rb +9 -0
- data/lib/picasa/default_photo.rb +6 -0
- data/lib/picasa/default_user.rb +6 -0
- data/lib/picasa/http/album.rb +113 -0
- data/lib/picasa/http/authentication.rb +40 -0
- data/lib/picasa/http/photo.rb +117 -0
- data/lib/picasa/missing.rb +22 -0
- data/lib/picasa/photo.rb +190 -0
- data/lib/picasa/template/album.xml.erb +20 -0
- data/lib/picasa/template/photo.erb +15 -0
- data/lib/picasa/user.rb +57 -0
- data/lib/picasa/util.rb +33 -0
- data/script.rb +46 -0
- data/spec/album_spec.rb +245 -0
- data/spec/authentication_spec.rb +19 -0
- data/spec/default_classes_spec.rb +50 -0
- data/spec/fixture/photo.jpg +0 -0
- data/spec/fixture/photo2.jpg +0 -0
- data/spec/generators/user_class_generator_spec.rb +40 -0
- data/spec/http/album_spec.rb +129 -0
- data/spec/http/authentication_spec.rb +15 -0
- data/spec/http/photo_spec.rb +78 -0
- data/spec/http_response_helper.rb +23 -0
- data/spec/mock_helper.rb +113 -0
- data/spec/photo_spec.rb +201 -0
- data/spec/spec_helper.rb +151 -0
- data/spec/suites/all.rb +14 -0
- data/spec/suites/all_mocked.rb +5 -0
- data/spec/user_spec.rb +74 -0
- metadata +222 -0
data/README.rdoc
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
=Go Picasa go
|
2
|
+
|
3
|
+
Go Picasa go is intended as library written in ruby to manipulate
|
4
|
+
Picasa[http://picasaweb.google.com/] albums and photos in a easy way. The idea
|
5
|
+
is to provide behaviors to ordinary objects so they can create, retrieve,
|
6
|
+
update and delete albums and photos in a more object oritented way, lefting
|
7
|
+
behind all the HTTP talk that was necessary previouly to interect with this service
|
8
|
+
provided by Google.
|
9
|
+
|
10
|
+
This library was implemented based on the
|
11
|
+
Protocol Guide[http://code.google.com/intl/pt-BR/apis/picasaweb/docs/2.0/developers_guide_protocol.html]
|
12
|
+
version 2.0 of Picasa Web Albums Data API.
|
13
|
+
|
14
|
+
Go Picasa go is still under heavy development but it's available for testing.
|
15
|
+
We will be glad if you can do some tests and give us your feedback. Thank you.
|
16
|
+
|
17
|
+
==Quick Start
|
18
|
+
|
19
|
+
On the command line, run the user_class generator to create a file with the authentication token and other stuff you need:
|
20
|
+
|
21
|
+
go-picasa-go user_class YourUserClass google_user_id, google_password
|
22
|
+
|
23
|
+
After running the command above, a file called "your_user_class.rb" will be
|
24
|
+
generated at the current folder you're at. The google user id and google password
|
25
|
+
are only necessary to generate the authentication token for further operation
|
26
|
+
with Go-picasa-go. It's also important for you to know that the password is only
|
27
|
+
used on this single operation. All other operations executed by the gem uses only
|
28
|
+
the authentication token generated.
|
29
|
+
|
30
|
+
==Usage
|
31
|
+
|
32
|
+
=== Your User
|
33
|
+
|
34
|
+
user = YourUserClass.new
|
35
|
+
|
36
|
+
===Working with albums
|
37
|
+
|
38
|
+
To create an album:
|
39
|
+
|
40
|
+
album = Picasa::DefaultAlbum.new
|
41
|
+
album.user = user
|
42
|
+
album.title = "Title"
|
43
|
+
album.summary = "Summary"
|
44
|
+
album.location = "Location"
|
45
|
+
album.keywords = "Keyword, another keyword"
|
46
|
+
album.access = 'private' # Other options: public, protected
|
47
|
+
|
48
|
+
album.picasa_save # Returns true or false
|
49
|
+
album.picasa_save! # Raise exception in case of not being able to save the album
|
50
|
+
|
51
|
+
To update that album:
|
52
|
+
|
53
|
+
album.title = "Updating the title"
|
54
|
+
|
55
|
+
album.picasa_update # Returns true or false
|
56
|
+
album.picasa_update! # Raise exception in case of not being able to update the album
|
57
|
+
|
58
|
+
To destroy an album:
|
59
|
+
|
60
|
+
album.picasa_destroy # Returns true or false
|
61
|
+
album.picasa_destroy! # Raise exception in case of not being able to destroy the album
|
62
|
+
|
63
|
+
To retrieve all albums from an user:
|
64
|
+
|
65
|
+
user.albums
|
66
|
+
|
67
|
+
To retrieve one specific album
|
68
|
+
|
69
|
+
user.find_album album.picasa_id
|
70
|
+
|
71
|
+
===Working with photos
|
72
|
+
|
73
|
+
To create a new photo:
|
74
|
+
|
75
|
+
photo = Picasa::DefaultPhoto.new
|
76
|
+
photo.album = album
|
77
|
+
photo.description = "Photo summary"
|
78
|
+
photo.file = File.open 'path/photo.jpg'
|
79
|
+
|
80
|
+
photo.picasa_save # Returns true or false
|
81
|
+
photo.picasa_save! # Raise exception in case of not being able to save the photo
|
82
|
+
|
83
|
+
To update an existing photo:
|
84
|
+
|
85
|
+
photo.title = "Updating title"
|
86
|
+
photo.description = "Updating summary"
|
87
|
+
photo.file = File.open 'path/new_photo.jpg'
|
88
|
+
|
89
|
+
photo.picasa_update # Returns true or false
|
90
|
+
photo.picasa_update! # Raise exception in case of not being able to update the photo
|
91
|
+
|
92
|
+
To destroy an existing photo:
|
93
|
+
|
94
|
+
photo.picasa_destroy # Returns true or false
|
95
|
+
photo.picasa_destroy! # Raise exception in case of not being able to delete the photo
|
96
|
+
|
97
|
+
To retrieve all photos from an album:
|
98
|
+
|
99
|
+
album.photos
|
100
|
+
|
101
|
+
To find an specific photo from an album:
|
102
|
+
|
103
|
+
album.find_photo photo.id
|
104
|
+
|
105
|
+
== More detailed configuration
|
106
|
+
|
107
|
+
If you need your own classes to interact to Picasa you can do it like this:
|
108
|
+
|
109
|
+
class MyUser
|
110
|
+
act_as_picasa_user
|
111
|
+
has_many_picasa_albums :class_name => "MyAlbum"
|
112
|
+
|
113
|
+
def picasa_id
|
114
|
+
'your_google_user_id'
|
115
|
+
end
|
116
|
+
|
117
|
+
def auth_token
|
118
|
+
'DQAAAHsAAAAdMyvdNfPg_iTFD-T_u6bBb-9Be...'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class MyAlbum
|
123
|
+
acts_as_picasa_album
|
124
|
+
belongs_to_picasa_user :class_name => "MyUser"
|
125
|
+
has_many_picasa_photos :class_name => "MyPhoto"
|
126
|
+
end
|
127
|
+
|
128
|
+
class MyPhoto
|
129
|
+
acts_as_picasa_photo
|
130
|
+
belongs_to_picasa_album :class_name => "MyAlbum"
|
131
|
+
end
|
132
|
+
|
133
|
+
We provided this kind of configuration so your classes can interact with other
|
134
|
+
frameworks like Rails and inherit from ActiveRecord::Base for example.
|
135
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "go-picasa-go"
|
5
|
+
gemspec.summary = "API to easly manipulate picasa albums and photos"
|
6
|
+
gemspec.description = "Go Picasa go is intended as library written in ruby to manipulate Picasa albums and photos in a easy way. The idea is to provide behaviors to ordinary objects so they can create, retrieve, update and delete albums and photos in a more object oritented way, lefting behind all the HTTP talk that was necessary previouly to interect with this service provided by Google."
|
7
|
+
|
8
|
+
gemspec.add_dependency 'nokogiri', '>= 1.4.3.1'
|
9
|
+
|
10
|
+
gemspec.email = "pedro.capaca@gmail.com"
|
11
|
+
gemspec.homepage = "http://github.com/capaca/go-picasa-go"
|
12
|
+
gemspec.authors = ["Pedro Dias"]
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
16
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
- Tentar melhorar o desempenho das operações
|
2
|
+
- Implement the update_attributes method for Picasa::Photo
|
3
|
+
- Testar o erro na forma de navegação no xml sem namespaces
|
4
|
+
- Verificar o esquema de atualização dos dados do album. Melhor usar o template?
|
5
|
+
- Testar que o access está sendo setado no params ao atualizar um album
|
6
|
+
- Testar que o access está sendo setado no params ao criar um novo album
|
7
|
+
- Corrigir o problema do numero de parametros no method missing
|
8
|
+
- Fazer o find lançar excessao caso não ache o registro.
|
9
|
+
|
10
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/go-picasa-go
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'go_picasa_go'
|
5
|
+
|
6
|
+
class Generator
|
7
|
+
|
8
|
+
def run args
|
9
|
+
@args = args
|
10
|
+
@generation = @args[0]
|
11
|
+
generate
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def generate
|
17
|
+
case @generation
|
18
|
+
when "user_class"
|
19
|
+
generate_user_class
|
20
|
+
when "auth_token"
|
21
|
+
generate_auth_token
|
22
|
+
else
|
23
|
+
puts "Usage:\n\tgo-picasa-go user_class [class_name]] [picasa_id] [password]\n\tgo-picasa-go auth_token [picasa_id] [password]"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_user_class
|
28
|
+
file_name = @args[1]
|
29
|
+
picasa_id = @args[2]
|
30
|
+
password = @args[3]
|
31
|
+
|
32
|
+
if validate file_name and validate picasa_id and validate password
|
33
|
+
UserClassGenerator.generate file_name, picasa_id, password
|
34
|
+
puts "File generated succefully!"
|
35
|
+
else
|
36
|
+
puts "Usage for user_class generation:\n\t go-picasa-go user_class [class_name] [picasa_id] [password]"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate_auth_token
|
41
|
+
picasa_id = @args[1]
|
42
|
+
password = @args[2]
|
43
|
+
|
44
|
+
if validate picasa_id and validate password
|
45
|
+
Picasa::Authentication.authenticate picasa_id, password
|
46
|
+
else
|
47
|
+
puts "Usage for auth_token generation:\n\t go-picasa-go auth_token [picasa_id] [password]"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate arg
|
52
|
+
if arg and arg.length > 0
|
53
|
+
return true
|
54
|
+
end
|
55
|
+
false
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
Generator.new.run ARGV
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
@@ -0,0 +1,243 @@
|
|
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" templates
|
7
|
+
that are primarily responsible for inserting pre-built data in between HTML tags.
|
8
|
+
The model contains the "smart" domain objects (such as Account, Product, Person,
|
9
|
+
Post) that holds all the business logic and knows how to persist themselves to
|
10
|
+
a database. The controller handles the incoming requests (such as Save New Account,
|
11
|
+
Update Product, Show Post) by manipulating the model and directing data to the view.
|
12
|
+
|
13
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
14
|
+
layer entitled Active Record. This layer allows you to present the data from
|
15
|
+
database rows as objects and embellish these data objects with business logic
|
16
|
+
methods. You can read more about Active Record in
|
17
|
+
link:files/vendor/rails/activerecord/README.html.
|
18
|
+
|
19
|
+
The controller and view are handled by the Action Pack, which handles both
|
20
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
21
|
+
are bundled in a single package due to their heavy interdependence. This is
|
22
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
23
|
+
more separate. Each of these packages can be used independently outside of
|
24
|
+
Rails. You can read more about Action Pack in
|
25
|
+
link:files/vendor/rails/actionpack/README.html.
|
26
|
+
|
27
|
+
|
28
|
+
== Getting Started
|
29
|
+
|
30
|
+
1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
|
31
|
+
and your application name. Ex: rails myapp
|
32
|
+
2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
|
33
|
+
3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
|
34
|
+
4. Follow the guidelines to start developing your application
|
35
|
+
|
36
|
+
|
37
|
+
== Web Servers
|
38
|
+
|
39
|
+
By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
|
40
|
+
with a variety of other web servers.
|
41
|
+
|
42
|
+
Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
|
43
|
+
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
|
44
|
+
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
|
45
|
+
More info at: http://mongrel.rubyforge.org
|
46
|
+
|
47
|
+
Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
|
48
|
+
Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
|
49
|
+
FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
|
50
|
+
|
51
|
+
== Apache .htaccess example for FCGI/CGI
|
52
|
+
|
53
|
+
# General Apache options
|
54
|
+
AddHandler fastcgi-script .fcgi
|
55
|
+
AddHandler cgi-script .cgi
|
56
|
+
Options +FollowSymLinks +ExecCGI
|
57
|
+
|
58
|
+
# If you don't want Rails to look in certain directories,
|
59
|
+
# use the following rewrite rules so that Apache won't rewrite certain requests
|
60
|
+
#
|
61
|
+
# Example:
|
62
|
+
# RewriteCond %{REQUEST_URI} ^/notrails.*
|
63
|
+
# RewriteRule .* - [L]
|
64
|
+
|
65
|
+
# Redirect all requests not available on the filesystem to Rails
|
66
|
+
# By default the cgi dispatcher is used which is very slow
|
67
|
+
#
|
68
|
+
# For better performance replace the dispatcher with the fastcgi one
|
69
|
+
#
|
70
|
+
# Example:
|
71
|
+
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
|
72
|
+
RewriteEngine On
|
73
|
+
|
74
|
+
# If your Rails application is accessed via an Alias directive,
|
75
|
+
# then you MUST also set the RewriteBase in this htaccess file.
|
76
|
+
#
|
77
|
+
# Example:
|
78
|
+
# Alias /myrailsapp /path/to/myrailsapp/public
|
79
|
+
# RewriteBase /myrailsapp
|
80
|
+
|
81
|
+
RewriteRule ^$ index.html [QSA]
|
82
|
+
RewriteRule ^([^.]+)$ $1.html [QSA]
|
83
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
84
|
+
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
|
85
|
+
|
86
|
+
# In case Rails experiences terminal errors
|
87
|
+
# Instead of displaying this message you can supply a file here which will be rendered instead
|
88
|
+
#
|
89
|
+
# Example:
|
90
|
+
# ErrorDocument 500 /500.html
|
91
|
+
|
92
|
+
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
|
93
|
+
|
94
|
+
|
95
|
+
== Debugging Rails
|
96
|
+
|
97
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
98
|
+
will help you debug it and get it back on the rails.
|
99
|
+
|
100
|
+
First area to check is the application log files. Have "tail -f" commands running
|
101
|
+
on the server.log and development.log. Rails will automatically display debugging
|
102
|
+
and runtime information to these files. Debugging info will also be shown in the
|
103
|
+
browser on requests from 127.0.0.1.
|
104
|
+
|
105
|
+
You can also log your own messages directly into the log file from your code using
|
106
|
+
the Ruby logger class from inside your controllers. Example:
|
107
|
+
|
108
|
+
class WeblogController < ActionController::Base
|
109
|
+
def destroy
|
110
|
+
@weblog = Weblog.find(params[:id])
|
111
|
+
@weblog.destroy
|
112
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
The result will be a message in your log file along the lines of:
|
117
|
+
|
118
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
|
119
|
+
|
120
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
121
|
+
|
122
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
|
123
|
+
|
124
|
+
* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
|
125
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
126
|
+
|
127
|
+
These two online (and free) books will bring you up to speed on the Ruby language
|
128
|
+
and also on programming in general.
|
129
|
+
|
130
|
+
|
131
|
+
== Debugger
|
132
|
+
|
133
|
+
Debugger support is available through the debugger command when you start your Mongrel or
|
134
|
+
Webrick server with --debugger. This means that you can break out of execution at any point
|
135
|
+
in the code, investigate and change the model, AND then resume execution!
|
136
|
+
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
|
137
|
+
Example:
|
138
|
+
|
139
|
+
class WeblogController < ActionController::Base
|
140
|
+
def index
|
141
|
+
@posts = Post.find(:all)
|
142
|
+
debugger
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
So the controller will accept the action, run the first line, then present you
|
147
|
+
with a IRB prompt in the server window. Here you can do things like:
|
148
|
+
|
149
|
+
>> @posts.inspect
|
150
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
151
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
152
|
+
>> @posts.first.title = "hello from a debugger"
|
153
|
+
=> "hello from a debugger"
|
154
|
+
|
155
|
+
...and even better is that you can examine how your runtime objects actually work:
|
156
|
+
|
157
|
+
>> f = @posts.first
|
158
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
159
|
+
>> f.
|
160
|
+
Display all 152 possibilities? (y or n)
|
161
|
+
|
162
|
+
Finally, when you're ready to resume execution, you enter "cont"
|
163
|
+
|
164
|
+
|
165
|
+
== Console
|
166
|
+
|
167
|
+
You can interact with the domain model by starting the console through <tt>script/console</tt>.
|
168
|
+
Here you'll have all parts of the application configured, just like it is when the
|
169
|
+
application is running. You can inspect domain models, change values, and save to the
|
170
|
+
database. Starting the script without arguments will launch it in the development environment.
|
171
|
+
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
172
|
+
|
173
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
174
|
+
|
175
|
+
== dbconsole
|
176
|
+
|
177
|
+
You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
|
178
|
+
You would be connected to the database with the credentials defined in database.yml.
|
179
|
+
Starting the script without arguments will connect you to the development database. Passing an
|
180
|
+
argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
|
181
|
+
Currently works for mysql, postgresql and sqlite.
|
182
|
+
|
183
|
+
== Description of Contents
|
184
|
+
|
185
|
+
app
|
186
|
+
Holds all the code that's specific to this particular application.
|
187
|
+
|
188
|
+
app/controllers
|
189
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
190
|
+
automated URL mapping. All controllers should descend from ApplicationController
|
191
|
+
which itself descends from ActionController::Base.
|
192
|
+
|
193
|
+
app/models
|
194
|
+
Holds models that should be named like post.rb.
|
195
|
+
Most models will descend from ActiveRecord::Base.
|
196
|
+
|
197
|
+
app/views
|
198
|
+
Holds the template files for the view that should be named like
|
199
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
|
200
|
+
syntax.
|
201
|
+
|
202
|
+
app/views/layouts
|
203
|
+
Holds the template files for layouts to be used with views. This models the common
|
204
|
+
header/footer method of wrapping views. In your views, define a layout using the
|
205
|
+
<tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
|
206
|
+
call <% yield %> to render the view using this layout.
|
207
|
+
|
208
|
+
app/helpers
|
209
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are generated
|
210
|
+
for you automatically when using script/generate for controllers. Helpers can be used to
|
211
|
+
wrap functionality for your views into methods.
|
212
|
+
|
213
|
+
config
|
214
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
215
|
+
|
216
|
+
db
|
217
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
218
|
+
the sequence of Migrations for your schema.
|
219
|
+
|
220
|
+
doc
|
221
|
+
This directory is where your application documentation will be stored when generated
|
222
|
+
using <tt>rake doc:app</tt>
|
223
|
+
|
224
|
+
lib
|
225
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
226
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
227
|
+
|
228
|
+
public
|
229
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
230
|
+
and javascripts. Also contains the dispatchers and the default HTML files. This should be
|
231
|
+
set as the DOCUMENT_ROOT of your web server.
|
232
|
+
|
233
|
+
script
|
234
|
+
Helper scripts for automation and generation.
|
235
|
+
|
236
|
+
test
|
237
|
+
Unit and functional tests along with fixtures. When using the script/generate scripts, template
|
238
|
+
test files will be generated for you and placed in this directory.
|
239
|
+
|
240
|
+
vendor
|
241
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
242
|
+
If the app has frozen rails, those gems also go here, under vendor/rails/.
|
243
|
+
This directory is in the load path.
|