amrita2 2.0.1 → 2.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.
- data/README +5 -5
- data/Rakefile +85 -0
- data/lib/amrita2/gettext.rb +9 -4
- data/lib/amrita2/template.rb +20 -9
- data/lib/amrita2/testsupport.rb +25 -0
- data/lib/amrita2/version.rb +1 -1
- data/sample/depot/README +160 -0
- data/sample/depot/Rakefile +10 -0
- data/sample/depot/app/views/admin/_form.html.a2 +23 -0
- data/sample/depot/app/views/admin/_form.html.erb +14 -0
- data/sample/depot/app/views/admin/edit.html.a2 +22 -0
- data/sample/depot/app/views/admin/edit.html.erb +10 -0
- data/sample/depot/app/views/admin/list.html.a2 +34 -0
- data/sample/depot/app/views/admin/list.html.erb +37 -0
- data/sample/depot/app/views/admin/new.html.a2 +21 -0
- data/sample/depot/app/views/admin/new.html.erb +9 -0
- data/sample/depot/app/views/admin/show.html.a2 +12 -0
- data/sample/depot/app/views/admin/show.html.erb +13 -0
- data/sample/depot/app/views/info/who_bought.rhtml +14 -0
- data/sample/depot/app/views/info/who_bought.rxml +8 -0
- data/sample/depot/app/views/layouts/admin.a2html +32 -0
- data/sample/depot/app/views/layouts/admin.rhtml +40 -0
- data/sample/depot/app/views/layouts/store.a2html +37 -0
- data/sample/depot/app/views/layouts/store.rhtml +43 -0
- data/sample/depot/app/views/login/add_user.rhtml +33 -0
- data/sample/depot/app/views/login/index.rhtml +9 -0
- data/sample/depot/app/views/login/list_users.rhtml +20 -0
- data/sample/depot/app/views/login/login.rhtml +26 -0
- data/sample/depot/app/views/store/_cart.html.a2 +18 -0
- data/sample/depot/app/views/store/_cart.html.erb +17 -0
- data/sample/depot/app/views/store/_cart_item.html.a2 +16 -0
- data/sample/depot/app/views/store/_cart_item.html.erb +14 -0
- data/sample/depot/app/views/store/add_to_cart.rjs +11 -0
- data/sample/depot/app/views/store/checkout.html.a2 +45 -0
- data/sample/depot/app/views/store/checkout.html.a2.using_macro +32 -0
- data/sample/depot/app/views/store/checkout.html.a2.without_label +37 -0
- data/sample/depot/app/views/store/checkout.html.erb +41 -0
- data/sample/depot/app/views/store/index.html.a2 +19 -0
- data/sample/depot/app/views/store/index.html.erb +22 -0
- data/sample/depot/config/database.yml +24 -0
- data/sample/depot/db/create_database.sql +14 -0
- data/sample/depot/doc/README_FOR_APP +35 -0
- data/sample/depot/lib/tasks/db_schema_version.rake +6 -0
- data/sample/depot/log/development.log +116 -0
- data/sample/depot/log/test.log +347 -0
- data/sample/depot/public/404.html +13 -0
- data/sample/depot/public/500.html +13 -0
- data/sample/depot/public/dispatch.cgi +10 -0
- data/sample/depot/public/dispatch.fcgi +24 -0
- data/sample/depot/public/favicon.ico +0 -0
- data/sample/depot/public/images/auto.jpg +0 -0
- data/sample/depot/public/images/logo.png +0 -0
- data/sample/depot/public/images/rails.png +0 -0
- data/sample/depot/public/images/svn.jpg +0 -0
- data/sample/depot/public/images/utc.jpg +0 -0
- data/sample/depot/public/index.html +282 -0
- data/sample/depot/public/javascripts/application.js +2 -0
- data/sample/depot/public/javascripts/controls.js +832 -0
- data/sample/depot/public/javascripts/dragdrop.js +942 -0
- data/sample/depot/public/javascripts/effects.js +954 -0
- data/sample/depot/public/javascripts/prototype.js +2347 -0
- data/sample/depot/public/robots.txt +1 -0
- data/sample/depot/public/stylesheets/depot.css +227 -0
- data/sample/depot/public/stylesheets/scaffold.css +74 -0
- data/sample/depot/script/about +3 -0
- data/sample/depot/script/breakpointer +3 -0
- data/sample/depot/script/console +3 -0
- data/sample/depot/script/destroy +3 -0
- data/sample/depot/script/generate +3 -0
- data/sample/depot/script/performance/benchmarker +3 -0
- data/sample/depot/script/performance/profiler +3 -0
- data/sample/depot/script/plugin +3 -0
- data/sample/depot/script/process/inspector +3 -0
- data/sample/depot/script/process/reaper +3 -0
- data/sample/depot/script/process/spawner +3 -0
- data/sample/depot/script/runner +3 -0
- data/sample/depot/script/server +3 -0
- data/sample/depot/test/fixtures/line_items.yml +16 -0
- data/sample/depot/test/fixtures/orders.yml +4 -0
- data/sample/depot/test/fixtures/performance/products.yml +8 -0
- data/sample/depot/test/fixtures/products.yml +16 -0
- data/sample/depot/test/fixtures/users.yml +7 -0
- data/sample/depot/vendor/plugins/will_paginate/LICENSE +18 -0
- data/sample/depot/vendor/plugins/will_paginate/README +171 -0
- data/sample/depot/vendor/plugins/will_paginate/Rakefile +27 -0
- data/sample/depot/vendor/plugins/will_paginate/test/console +9 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/companies.yml +24 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml +13 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/projects.yml +7 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/replies.yml +34 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/schema.sql +44 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/topics.yml +30 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/users.yml +35 -0
- data/sample/login_engine/README +182 -0
- data/sample/login_engine/Rakefile +27 -0
- data/sample/login_engine/app/views/layouts/user.a2html +20 -0
- data/sample/login_engine/app/views/layouts/user.rhtml +16 -0
- data/sample/login_engine/app/views/user/_edit.a2html +16 -0
- data/sample/login_engine/app/views/user/_edit.rhtml +11 -0
- data/sample/login_engine/app/views/user/_password.a2html +18 -0
- data/sample/login_engine/app/views/user/_password.rhtml +9 -0
- data/sample/login_engine/app/views/user/change_password.a2html +17 -0
- data/sample/login_engine/app/views/user/change_password.rhtml +17 -0
- data/sample/login_engine/app/views/user/edit.a2html +22 -0
- data/sample/login_engine/app/views/user/edit.rhtml +23 -0
- data/sample/login_engine/app/views/user/forgot_password.rhtml +18 -0
- data/sample/login_engine/app/views/user/home.a2html +12 -0
- data/sample/login_engine/app/views/user/home.rhtml +7 -0
- data/sample/login_engine/app/views/user/login.a2html +16 -0
- data/sample/login_engine/app/views/user/login.rhtml +17 -0
- data/sample/login_engine/app/views/user/logout.rhtml +8 -0
- data/sample/login_engine/app/views/user/signup.a2html +14 -0
- data/sample/login_engine/app/views/user/signup.rhtml +17 -0
- data/sample/login_engine/app/views/user_notify/change_password.rhtml +10 -0
- data/sample/login_engine/app/views/user_notify/delete.rhtml +5 -0
- data/sample/login_engine/app/views/user_notify/forgot_password.rhtml +11 -0
- data/sample/login_engine/app/views/user_notify/pending_delete.rhtml +9 -0
- data/sample/login_engine/app/views/user_notify/signup.rhtml +12 -0
- data/sample/login_engine/config/database.yml +18 -0
- data/sample/login_engine/db/create_database.sql +14 -0
- data/sample/login_engine/db/dev.sqlite3 +0 -0
- data/sample/login_engine/db/test.sqlite3 +0 -0
- data/sample/login_engine/doc/README_FOR_APP +2 -0
- data/sample/login_engine/locale/ja/LC_MESSAGES/login_engine.mo +0 -0
- data/sample/login_engine/log/development.log +330 -0
- data/sample/login_engine/log/test.log +19026 -0
- data/sample/login_engine/po/ja/login_engine.po +248 -0
- data/sample/login_engine/po/login_engine.pot +245 -0
- data/sample/login_engine/public/404.html +30 -0
- data/sample/login_engine/public/500.html +30 -0
- data/sample/login_engine/public/dispatch.cgi +10 -0
- data/sample/login_engine/public/dispatch.fcgi +24 -0
- data/sample/login_engine/public/favicon.ico +0 -0
- data/sample/login_engine/public/images/rails.png +0 -0
- data/sample/login_engine/public/index.html +277 -0
- data/sample/login_engine/public/javascripts/application.js +2 -0
- data/sample/login_engine/public/javascripts/controls.js +833 -0
- data/sample/login_engine/public/javascripts/dragdrop.js +942 -0
- data/sample/login_engine/public/javascripts/effects.js +1088 -0
- data/sample/login_engine/public/javascripts/prototype.js +2385 -0
- data/sample/login_engine/public/robots.txt +1 -0
- data/sample/login_engine/public/stylesheets/login_engine.css +81 -0
- data/sample/login_engine/script/about +3 -0
- data/sample/login_engine/script/breakpointer +3 -0
- data/sample/login_engine/script/console +3 -0
- data/sample/login_engine/script/destroy +3 -0
- data/sample/login_engine/script/generate +3 -0
- data/sample/login_engine/script/performance/benchmarker +3 -0
- data/sample/login_engine/script/performance/profiler +3 -0
- data/sample/login_engine/script/plugin +3 -0
- data/sample/login_engine/script/process/inspector +3 -0
- data/sample/login_engine/script/process/reaper +3 -0
- data/sample/login_engine/script/process/spawner +3 -0
- data/sample/login_engine/script/runner +3 -0
- data/sample/login_engine/script/server +3 -0
- data/sample/login_engine/test/fixtures/users.yml +41 -0
- data/specs/erb_cdata.rb +11 -0
- data/specs/filters.rb +5 -4
- data/specs/gettext/static_text.rb +30 -13
- data/specs/impl/preprocess.rb +58 -54
- metadata +375 -120
- data/sample/hello/test1.rb +0 -23
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
= WillPaginate
|
|
2
|
+
|
|
3
|
+
Pagination is just limiting the number of records displayed. Why should you let
|
|
4
|
+
it get in your way while developing, then? This plugin makes magic happen. Did
|
|
5
|
+
you ever want to be able to do just this on a model:
|
|
6
|
+
|
|
7
|
+
Post.paginate :page => 1
|
|
8
|
+
|
|
9
|
+
... and then render the page links with a single view helper? Well, now you
|
|
10
|
+
can.
|
|
11
|
+
|
|
12
|
+
Ryan Bates made an awesome screencast[http://railscasts.com/episodes/51],
|
|
13
|
+
check it out.
|
|
14
|
+
|
|
15
|
+
Your mind reels with questions? Join our Google
|
|
16
|
+
group[http://groups.google.com/group/will_paginate].
|
|
17
|
+
|
|
18
|
+
== Install the plugin
|
|
19
|
+
|
|
20
|
+
Simply do:
|
|
21
|
+
|
|
22
|
+
script/plugin install svn://errtheblog.com/svn/plugins/will_paginate
|
|
23
|
+
|
|
24
|
+
Alternatively, you can add the whole Err repository to plugin sources:
|
|
25
|
+
|
|
26
|
+
script/plugin source svn://errtheblog.com/svn/plugins
|
|
27
|
+
|
|
28
|
+
You only have to do this once, then you can install will_paginate to each of your applications simply like this:
|
|
29
|
+
|
|
30
|
+
script/plugin install will_paginate
|
|
31
|
+
|
|
32
|
+
To see what other plugins are now available to you, list the newly added plugin source:
|
|
33
|
+
|
|
34
|
+
script/plugin list --source=svn://errtheblog.com/svn/plugins
|
|
35
|
+
|
|
36
|
+
The plugin officially supports Rails versions 1.2.6 and 2.0.2. You can browse
|
|
37
|
+
its source code on Warehouse: http://plugins.require.errtheblog.com/browser/will_paginate
|
|
38
|
+
|
|
39
|
+
== Example usage
|
|
40
|
+
|
|
41
|
+
Use a paginate finder in the controller:
|
|
42
|
+
|
|
43
|
+
@posts = Post.paginate_by_board_id @board.id, :page => params[:page]
|
|
44
|
+
|
|
45
|
+
Yeah, +paginate+ works just like +find+ -- it just doesn't fetch all the
|
|
46
|
+
records. Don't forget to tell it which page you want, or it will complain!
|
|
47
|
+
Read more on WillPaginate::Finder::ClassMethods.
|
|
48
|
+
|
|
49
|
+
Render the posts in your view like you would normally do. When you need to render
|
|
50
|
+
pagination, just stick this in:
|
|
51
|
+
|
|
52
|
+
<%= will_paginate @posts %>
|
|
53
|
+
|
|
54
|
+
You're done. (Copy and paste the example fancy CSS styles from the bottom.) You
|
|
55
|
+
can find the option list at WillPaginate::ViewHelpers.
|
|
56
|
+
|
|
57
|
+
How does it know how much items to fetch per page? It asks your model by calling
|
|
58
|
+
its <tt>per_page</tt> class method. You can define it like this:
|
|
59
|
+
|
|
60
|
+
class Post < ActiveRecord::Base
|
|
61
|
+
cattr_reader :per_page
|
|
62
|
+
@@per_page = 50
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
... or like this:
|
|
66
|
+
|
|
67
|
+
class Post < ActiveRecord::Base
|
|
68
|
+
def self.per_page
|
|
69
|
+
50
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
... or don't worry about it at all. WillPaginate defines it to be <b>30</b> by default.
|
|
74
|
+
But you can always specify the count explicitly when calling +paginate+:
|
|
75
|
+
|
|
76
|
+
@posts = Post.paginate :page => params[:page], :per_page => 50
|
|
77
|
+
|
|
78
|
+
The +paginate+ finder wraps the original finder and returns your resultset that now has
|
|
79
|
+
some new properties. You can use the collection as you would with any ActiveRecord
|
|
80
|
+
resultset. WillPaginate view helpers also need that object to be able to render pagination:
|
|
81
|
+
|
|
82
|
+
<ol>
|
|
83
|
+
<% for post in @posts -%>
|
|
84
|
+
<li>Render `post` in some nice way.</li>
|
|
85
|
+
<% end -%>
|
|
86
|
+
</ol>
|
|
87
|
+
|
|
88
|
+
<p>Now let's render us some pagination!</p>
|
|
89
|
+
<%= will_paginate @posts %>
|
|
90
|
+
|
|
91
|
+
More detailed documentation:
|
|
92
|
+
|
|
93
|
+
* WillPaginate::Finder::ClassMethods for pagination on your models;
|
|
94
|
+
* WillPaginate::ViewHelpers for your views.
|
|
95
|
+
|
|
96
|
+
== Oh noes, a bug!
|
|
97
|
+
|
|
98
|
+
Tell us what happened so we can fix it, quick! Issues are filed on the Lighthouse project:
|
|
99
|
+
http://err.lighthouseapp.com/projects/466-plugins/tickets?q=tagged:will_paginate
|
|
100
|
+
|
|
101
|
+
Steps to make an awesome bug report:
|
|
102
|
+
|
|
103
|
+
1. Run <tt>rake test</tt> in the <i>will_paginate</i> directory. (You will need SQLite3.)
|
|
104
|
+
Copy the output if there are failing tests.
|
|
105
|
+
2. Register on Lighthouse to create a new ticket.
|
|
106
|
+
3. Write a descriptive, short title. Provide as much info as you can in the body.
|
|
107
|
+
Assign the ticket to Mislav and tag it with meaningful tags, <tt>"will_paginate"</tt>
|
|
108
|
+
being among them.
|
|
109
|
+
4. Yay! You will be notified on updates automatically.
|
|
110
|
+
|
|
111
|
+
Here is an example of a great bug report and patch:
|
|
112
|
+
http://err.lighthouseapp.com/projects/466/tickets/172-total_entries-ignored-in-paginate_by_sql
|
|
113
|
+
|
|
114
|
+
== Authors, credits, contact
|
|
115
|
+
|
|
116
|
+
Want to discuss, request features, ask questions? Join the Google group:
|
|
117
|
+
http://groups.google.com/group/will_paginate
|
|
118
|
+
|
|
119
|
+
Authors:: Mislav Marohnić, PJ Hyett
|
|
120
|
+
Original announcement:: http://errtheblog.com/post/929
|
|
121
|
+
Original PHP source:: http://www.strangerstudios.com/sandbox/pagination/diggstyle.php
|
|
122
|
+
|
|
123
|
+
All these people helped making will_paginate what it is now with their code
|
|
124
|
+
contributions or simply awesome ideas:
|
|
125
|
+
|
|
126
|
+
Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
|
|
127
|
+
Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
|
|
128
|
+
van Zuijlen, Maria, Brendan Ribera.
|
|
129
|
+
|
|
130
|
+
== Usable pagination in the UI
|
|
131
|
+
|
|
132
|
+
Copy the following CSS into your stylesheet for a good start:
|
|
133
|
+
|
|
134
|
+
.pagination {
|
|
135
|
+
padding: 3px;
|
|
136
|
+
margin: 3px;
|
|
137
|
+
}
|
|
138
|
+
.pagination a {
|
|
139
|
+
padding: 2px 5px 2px 5px;
|
|
140
|
+
margin: 2px;
|
|
141
|
+
border: 1px solid #aaaadd;
|
|
142
|
+
text-decoration: none;
|
|
143
|
+
color: #000099;
|
|
144
|
+
}
|
|
145
|
+
.pagination a:hover, .pagination a:active {
|
|
146
|
+
border: 1px solid #000099;
|
|
147
|
+
color: #000;
|
|
148
|
+
}
|
|
149
|
+
.pagination span.current {
|
|
150
|
+
padding: 2px 5px 2px 5px;
|
|
151
|
+
margin: 2px;
|
|
152
|
+
border: 1px solid #000099;
|
|
153
|
+
font-weight: bold;
|
|
154
|
+
background-color: #000099;
|
|
155
|
+
color: #FFF;
|
|
156
|
+
}
|
|
157
|
+
.pagination span.disabled {
|
|
158
|
+
padding: 2px 5px 2px 5px;
|
|
159
|
+
margin: 2px;
|
|
160
|
+
border: 1px solid #eee;
|
|
161
|
+
color: #ddd;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
More reading about pagination as design pattern:
|
|
165
|
+
|
|
166
|
+
* Pagination 101:
|
|
167
|
+
http://kurafire.net/log/archive/2007/06/22/pagination-101
|
|
168
|
+
* Pagination gallery:
|
|
169
|
+
http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/
|
|
170
|
+
* Pagination on Yahoo Design Pattern Library:
|
|
171
|
+
http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
require 'rake/rdoctask'
|
|
4
|
+
|
|
5
|
+
desc 'Default: run unit tests.'
|
|
6
|
+
task :default => :test
|
|
7
|
+
|
|
8
|
+
desc 'Test the will_paginate plugin.'
|
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
|
10
|
+
t.pattern = 'test/**/*_test.rb'
|
|
11
|
+
t.verbose = true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
desc 'Generate RDoc documentation for the will_paginate plugin.'
|
|
15
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
16
|
+
files = ['README', 'LICENSE', 'lib/**/*.rb']
|
|
17
|
+
rdoc.rdoc_files.add(files)
|
|
18
|
+
rdoc.main = "README" # page to start on
|
|
19
|
+
rdoc.title = "will_paginate"
|
|
20
|
+
|
|
21
|
+
templates = %w[/Users/chris/ruby/projects/err/rock/template.rb /var/www/rock/template.rb]
|
|
22
|
+
rdoc.template = templates.find { |t| File.exists? t }
|
|
23
|
+
|
|
24
|
+
rdoc.rdoc_dir = 'doc' # rdoc output folder
|
|
25
|
+
rdoc.options << '--inline-source'
|
|
26
|
+
rdoc.options << '--charset=UTF-8'
|
|
27
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|
3
|
+
libs = []
|
|
4
|
+
dirname = File.dirname(__FILE__)
|
|
5
|
+
|
|
6
|
+
libs << 'irb/completion'
|
|
7
|
+
libs << File.join(dirname, 'lib', 'load_fixtures')
|
|
8
|
+
|
|
9
|
+
exec "#{irb}#{libs.map{ |l| " -r #{l}" }.join} --simple-prompt"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
thirty_seven_signals:
|
|
2
|
+
id: 1
|
|
3
|
+
name: 37Signals
|
|
4
|
+
rating: 4
|
|
5
|
+
|
|
6
|
+
TextDrive:
|
|
7
|
+
id: 2
|
|
8
|
+
name: TextDrive
|
|
9
|
+
rating: 4
|
|
10
|
+
|
|
11
|
+
PlanetArgon:
|
|
12
|
+
id: 3
|
|
13
|
+
name: Planet Argon
|
|
14
|
+
rating: 4
|
|
15
|
+
|
|
16
|
+
Google:
|
|
17
|
+
id: 4
|
|
18
|
+
name: Google
|
|
19
|
+
rating: 4
|
|
20
|
+
|
|
21
|
+
Ionist:
|
|
22
|
+
id: 5
|
|
23
|
+
name: Ioni.st
|
|
24
|
+
rating: 4
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
witty_retort:
|
|
2
|
+
id: 1
|
|
3
|
+
topic_id: 1
|
|
4
|
+
content: Birdman is better!
|
|
5
|
+
created_at: <%= 6.hours.ago.to_s(:db) %>
|
|
6
|
+
updated_at: nil
|
|
7
|
+
|
|
8
|
+
another:
|
|
9
|
+
id: 2
|
|
10
|
+
topic_id: 2
|
|
11
|
+
content: Nuh uh!
|
|
12
|
+
created_at: <%= 1.hour.ago.to_s(:db) %>
|
|
13
|
+
updated_at: nil
|
|
14
|
+
|
|
15
|
+
spam:
|
|
16
|
+
id: 3
|
|
17
|
+
topic_id: 1
|
|
18
|
+
content: Nice site!
|
|
19
|
+
created_at: <%= 1.hour.ago.to_s(:db) %>
|
|
20
|
+
updated_at: nil
|
|
21
|
+
|
|
22
|
+
decisive:
|
|
23
|
+
id: 4
|
|
24
|
+
topic_id: 4
|
|
25
|
+
content: "I'm getting to the bottom of this"
|
|
26
|
+
created_at: <%= 30.minutes.ago.to_s(:db) %>
|
|
27
|
+
updated_at: nil
|
|
28
|
+
|
|
29
|
+
brave:
|
|
30
|
+
id: 5
|
|
31
|
+
topic_id: 4
|
|
32
|
+
content: "AR doesn't scare me a bit"
|
|
33
|
+
created_at: <%= 10.minutes.ago.to_s(:db) %>
|
|
34
|
+
updated_at: nil
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
CREATE TABLE 'companies' (
|
|
2
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
|
3
|
+
'name' TEXT DEFAULT NULL,
|
|
4
|
+
'rating' INTEGER DEFAULT 1
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
CREATE TABLE 'replies' (
|
|
8
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
|
9
|
+
'content' text,
|
|
10
|
+
'created_at' datetime,
|
|
11
|
+
'updated_at' datetime,
|
|
12
|
+
'topic_id' integer
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE TABLE 'topics' (
|
|
16
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
|
17
|
+
'project_id' INTEGER DEFAULT NULL,
|
|
18
|
+
'title' varchar(255),
|
|
19
|
+
'subtitle' varchar(255),
|
|
20
|
+
'content' text,
|
|
21
|
+
'created_at' datetime,
|
|
22
|
+
'updated_at' datetime
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE TABLE 'users' (
|
|
26
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
|
27
|
+
'name' TEXT DEFAULT NULL,
|
|
28
|
+
'salary' INTEGER DEFAULT 70000,
|
|
29
|
+
'created_at' DATETIME DEFAULT NULL,
|
|
30
|
+
'updated_at' DATETIME DEFAULT NULL,
|
|
31
|
+
'type' TEXT DEFAULT NULL
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
CREATE TABLE 'projects' (
|
|
35
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
|
36
|
+
'name' TEXT DEFAULT NULL
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
CREATE TABLE 'developers_projects' (
|
|
40
|
+
'developer_id' INTEGER NOT NULL,
|
|
41
|
+
'project_id' INTEGER NOT NULL,
|
|
42
|
+
'joined_on' DATE DEFAULT NULL,
|
|
43
|
+
'access_level' INTEGER DEFAULT 1
|
|
44
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
futurama:
|
|
2
|
+
id: 1
|
|
3
|
+
title: Isnt futurama awesome?
|
|
4
|
+
subtitle: It really is, isnt it.
|
|
5
|
+
content: I like futurama
|
|
6
|
+
created_at: <%= 1.day.ago.to_s(:db) %>
|
|
7
|
+
updated_at:
|
|
8
|
+
|
|
9
|
+
harvey_birdman:
|
|
10
|
+
id: 2
|
|
11
|
+
title: Harvey Birdman is the king of all men
|
|
12
|
+
subtitle: yup
|
|
13
|
+
content: He really is
|
|
14
|
+
created_at: <%= 2.hours.ago.to_s(:db) %>
|
|
15
|
+
updated_at:
|
|
16
|
+
|
|
17
|
+
rails:
|
|
18
|
+
id: 3
|
|
19
|
+
project_id: 1
|
|
20
|
+
title: Rails is nice
|
|
21
|
+
subtitle: It makes me happy
|
|
22
|
+
content: except when I have to hack internals to fix pagination. even then really.
|
|
23
|
+
created_at: <%= 20.minutes.ago.to_s(:db) %>
|
|
24
|
+
|
|
25
|
+
ar:
|
|
26
|
+
id: 4
|
|
27
|
+
project_id: 1
|
|
28
|
+
title: ActiveRecord sometimes freaks me out
|
|
29
|
+
content: "I mean, what's the deal with eager loading?"
|
|
30
|
+
created_at: <%= 15.minutes.ago.to_s(:db) %>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
david:
|
|
2
|
+
id: 1
|
|
3
|
+
name: David
|
|
4
|
+
salary: 80000
|
|
5
|
+
type: Developer
|
|
6
|
+
|
|
7
|
+
jamis:
|
|
8
|
+
id: 2
|
|
9
|
+
name: Jamis
|
|
10
|
+
salary: 150000
|
|
11
|
+
type: Developer
|
|
12
|
+
|
|
13
|
+
<% for digit in 3..10 %>
|
|
14
|
+
dev_<%= digit %>:
|
|
15
|
+
id: <%= digit %>
|
|
16
|
+
name: fixture_<%= digit %>
|
|
17
|
+
salary: 100000
|
|
18
|
+
type: Developer
|
|
19
|
+
<% end %>
|
|
20
|
+
|
|
21
|
+
poor_jamis:
|
|
22
|
+
id: 11
|
|
23
|
+
name: Jamis
|
|
24
|
+
salary: 9000
|
|
25
|
+
type: Developer
|
|
26
|
+
|
|
27
|
+
admin:
|
|
28
|
+
id: 12
|
|
29
|
+
name: admin
|
|
30
|
+
type: Admin
|
|
31
|
+
|
|
32
|
+
goofy:
|
|
33
|
+
id: 13
|
|
34
|
+
name: Goofy
|
|
35
|
+
type: Admin
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
== Welcome to Rails
|
|
2
|
+
|
|
3
|
+
Rails is a web-application and persistence framework that includes everything
|
|
4
|
+
needed to create database-backed web-applications according to the
|
|
5
|
+
Model-View-Control pattern of separation. This pattern splits the view (also
|
|
6
|
+
called the presentation) into "dumb" templates that are primarily responsible
|
|
7
|
+
for inserting pre-built data in between HTML tags. The model contains the
|
|
8
|
+
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
|
9
|
+
the business logic and knows how to persist themselves to a database. The
|
|
10
|
+
controller handles the incoming requests (such as Save New Account, Update
|
|
11
|
+
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 rails command
|
|
31
|
+
and your application name. Ex: rails myapp
|
|
32
|
+
(If you've downloaded rails in a complete tgz or zip, this step is already done)
|
|
33
|
+
2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
|
|
34
|
+
3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
|
|
35
|
+
4. Follow the guidelines to start developing your application
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
== Web Servers
|
|
39
|
+
|
|
40
|
+
By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
|
|
41
|
+
Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server,
|
|
42
|
+
Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
|
|
43
|
+
that you can always get up and running quickly.
|
|
44
|
+
|
|
45
|
+
Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is
|
|
46
|
+
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
|
|
47
|
+
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
|
|
48
|
+
More info at: http://mongrel.rubyforge.org
|
|
49
|
+
|
|
50
|
+
If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
|
|
51
|
+
Mongrel and WEBrick and also suited for production use, but requires additional
|
|
52
|
+
installation and currently only works well on OS X/Unix (Windows users are encouraged
|
|
53
|
+
to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
|
|
54
|
+
http://www.lighttpd.net.
|
|
55
|
+
|
|
56
|
+
And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
|
|
57
|
+
web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
|
|
58
|
+
for production.
|
|
59
|
+
|
|
60
|
+
But of course its also possible to run Rails on any platform that supports FCGI.
|
|
61
|
+
Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
|
|
62
|
+
please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
== Debugging Rails
|
|
66
|
+
|
|
67
|
+
Have "tail -f" commands running on the server.log and development.log. Rails will
|
|
68
|
+
automatically display debugging and runtime information to these files. Debugging
|
|
69
|
+
info will also be shown in the browser on requests from 127.0.0.1.
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
== Breakpoints
|
|
73
|
+
|
|
74
|
+
Breakpoint support is available through the script/breakpointer client. This
|
|
75
|
+
means that you can break out of execution at any point in the code, investigate
|
|
76
|
+
and change the model, AND then resume execution! Example:
|
|
77
|
+
|
|
78
|
+
class WeblogController < ActionController::Base
|
|
79
|
+
def index
|
|
80
|
+
@posts = Post.find(:all)
|
|
81
|
+
breakpoint "Breaking out from the list"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
So the controller will accept the action, run the first line, then present you
|
|
86
|
+
with a IRB prompt in the breakpointer window. Here you can do things like:
|
|
87
|
+
|
|
88
|
+
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
|
89
|
+
|
|
90
|
+
>> @posts.inspect
|
|
91
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
|
92
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
|
93
|
+
>> @posts.first.title = "hello from a breakpoint"
|
|
94
|
+
=> "hello from a breakpoint"
|
|
95
|
+
|
|
96
|
+
...and even better is that you can examine how your runtime objects actually work:
|
|
97
|
+
|
|
98
|
+
>> f = @posts.first
|
|
99
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
|
100
|
+
>> f.
|
|
101
|
+
Display all 152 possibilities? (y or n)
|
|
102
|
+
|
|
103
|
+
Finally, when you're ready to resume execution, you press CTRL-D
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
== Console
|
|
107
|
+
|
|
108
|
+
You can interact with the domain model by starting the console through <tt>script/console</tt>.
|
|
109
|
+
Here you'll have all parts of the application configured, just like it is when the
|
|
110
|
+
application is running. You can inspect domain models, change values, and save to the
|
|
111
|
+
database. Starting the script without arguments will launch it in the development environment.
|
|
112
|
+
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
|
113
|
+
|
|
114
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
|
115
|
+
|
|
116
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
== Description of contents
|
|
121
|
+
|
|
122
|
+
app
|
|
123
|
+
Holds all the code that's specific to this particular application.
|
|
124
|
+
|
|
125
|
+
app/controllers
|
|
126
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
|
127
|
+
automated URL mapping. All controllers should descend from ApplicationController
|
|
128
|
+
which itself descends from ActionController::Base.
|
|
129
|
+
|
|
130
|
+
app/models
|
|
131
|
+
Holds models that should be named like post.rb.
|
|
132
|
+
Most models will descend from ActiveRecord::Base.
|
|
133
|
+
|
|
134
|
+
app/views
|
|
135
|
+
Holds the template files for the view that should be named like
|
|
136
|
+
weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby
|
|
137
|
+
syntax.
|
|
138
|
+
|
|
139
|
+
app/views/layouts
|
|
140
|
+
Holds the template files for layouts to be used with views. This models the common
|
|
141
|
+
header/footer method of wrapping views. In your views, define a layout using the
|
|
142
|
+
<tt>layout :default</tt> and create a file named default.rhtml. Inside default.rhtml,
|
|
143
|
+
call <% yield %> to render the view using this layout.
|
|
144
|
+
|
|
145
|
+
app/helpers
|
|
146
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are generated
|
|
147
|
+
for you automatically when using script/generate for controllers. Helpers can be used to
|
|
148
|
+
wrap functionality for your views into methods.
|
|
149
|
+
|
|
150
|
+
config
|
|
151
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
|
152
|
+
|
|
153
|
+
components
|
|
154
|
+
Self-contained mini-applications that can bundle together controllers, models, and views.
|
|
155
|
+
|
|
156
|
+
db
|
|
157
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
|
158
|
+
the sequence of Migrations for your schema.
|
|
159
|
+
|
|
160
|
+
doc
|
|
161
|
+
This directory is where your application documentation will be stored when generated
|
|
162
|
+
using <tt>rake doc:app</tt>
|
|
163
|
+
|
|
164
|
+
lib
|
|
165
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
|
166
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
|
167
|
+
|
|
168
|
+
public
|
|
169
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
|
170
|
+
and javascripts. Also contains the dispatchers and the default HTML files. This should be
|
|
171
|
+
set as the DOCUMENT_ROOT of your web server.
|
|
172
|
+
|
|
173
|
+
script
|
|
174
|
+
Helper scripts for automation and generation.
|
|
175
|
+
|
|
176
|
+
test
|
|
177
|
+
Unit and functional tests along with fixtures. When using the script/generate scripts, template
|
|
178
|
+
test files will be generated for you and placed in this directory.
|
|
179
|
+
|
|
180
|
+
vendor
|
|
181
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
|
182
|
+
This directory is in the load path.
|