watson-acts_as_ferret 0.4.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +104 -0
- data/acts_as_ferret.gemspec +58 -0
- data/bin/aaf_install +29 -0
- data/config/ferret_server.yml +24 -0
- data/doc/README.win32 +23 -0
- data/doc/demo/README +154 -0
- data/doc/demo/README_DEMO +23 -0
- data/doc/demo/Rakefile +10 -0
- data/doc/demo/app/controllers/admin/backend_controller.rb +14 -0
- data/doc/demo/app/controllers/admin_area_controller.rb +4 -0
- data/doc/demo/app/controllers/application.rb +5 -0
- data/doc/demo/app/controllers/contents_controller.rb +49 -0
- data/doc/demo/app/controllers/searches_controller.rb +8 -0
- data/doc/demo/app/helpers/admin/backend_helper.rb +2 -0
- data/doc/demo/app/helpers/application_helper.rb +3 -0
- data/doc/demo/app/helpers/content_helper.rb +2 -0
- data/doc/demo/app/helpers/search_helper.rb +2 -0
- data/doc/demo/app/models/comment.rb +48 -0
- data/doc/demo/app/models/content.rb +12 -0
- data/doc/demo/app/models/content_base.rb +28 -0
- data/doc/demo/app/models/search.rb +19 -0
- data/doc/demo/app/models/shared_index1.rb +3 -0
- data/doc/demo/app/models/shared_index2.rb +3 -0
- data/doc/demo/app/models/special_content.rb +3 -0
- data/doc/demo/app/models/stats.rb +20 -0
- data/doc/demo/app/views/admin/backend/search.rhtml +18 -0
- data/doc/demo/app/views/contents/_form.rhtml +10 -0
- data/doc/demo/app/views/contents/edit.rhtml +9 -0
- data/doc/demo/app/views/contents/index.rhtml +24 -0
- data/doc/demo/app/views/contents/new.rhtml +8 -0
- data/doc/demo/app/views/contents/show.rhtml +8 -0
- data/doc/demo/app/views/layouts/application.html.erb +17 -0
- data/doc/demo/app/views/searches/_content.html.erb +2 -0
- data/doc/demo/app/views/searches/search.html.erb +20 -0
- data/doc/demo/config/boot.rb +109 -0
- data/doc/demo/config/database.yml +38 -0
- data/doc/demo/config/environment.rb +69 -0
- data/doc/demo/config/environments/development.rb +16 -0
- data/doc/demo/config/environments/production.rb +19 -0
- data/doc/demo/config/environments/test.rb +21 -0
- data/doc/demo/config/ferret_server.yml +18 -0
- data/doc/demo/config/lighttpd.conf +40 -0
- data/doc/demo/config/routes.rb +9 -0
- data/doc/demo/db/development_structure.sql +15 -0
- data/doc/demo/db/migrate/001_initial_migration.rb +18 -0
- data/doc/demo/db/migrate/002_add_type_to_contents.rb +9 -0
- data/doc/demo/db/migrate/003_create_shared_index1s.rb +11 -0
- data/doc/demo/db/migrate/004_create_shared_index2s.rb +11 -0
- data/doc/demo/db/migrate/005_special_field.rb +9 -0
- data/doc/demo/db/migrate/006_create_stats.rb +15 -0
- data/doc/demo/db/schema.sql +18 -0
- data/doc/demo/db/schema.sqlite +14 -0
- data/doc/demo/doc/README_FOR_APP +2 -0
- data/doc/demo/doc/howto.txt +70 -0
- data/doc/demo/public/404.html +8 -0
- data/doc/demo/public/500.html +8 -0
- data/doc/demo/public/dispatch.cgi +10 -0
- data/doc/demo/public/dispatch.fcgi +24 -0
- data/doc/demo/public/dispatch.rb +10 -0
- data/doc/demo/public/favicon.ico +0 -0
- data/doc/demo/public/images/rails.png +0 -0
- data/doc/demo/public/index.html +277 -0
- data/doc/demo/public/robots.txt +1 -0
- data/doc/demo/public/stylesheets/scaffold.css +74 -0
- data/doc/demo/script/about +3 -0
- data/doc/demo/script/breakpointer +3 -0
- data/doc/demo/script/console +3 -0
- data/doc/demo/script/destroy +3 -0
- data/doc/demo/script/ferret_server +10 -0
- data/doc/demo/script/generate +3 -0
- data/doc/demo/script/performance/benchmarker +3 -0
- data/doc/demo/script/performance/profiler +3 -0
- data/doc/demo/script/plugin +3 -0
- data/doc/demo/script/process/inspector +3 -0
- data/doc/demo/script/process/reaper +3 -0
- data/doc/demo/script/process/spawner +3 -0
- data/doc/demo/script/process/spinner +3 -0
- data/doc/demo/script/runner +3 -0
- data/doc/demo/script/server +3 -0
- data/doc/demo/test/fixtures/comments.yml +12 -0
- data/doc/demo/test/fixtures/contents.yml +13 -0
- data/doc/demo/test/fixtures/remote_contents.yml +9 -0
- data/doc/demo/test/fixtures/shared_index1s.yml +7 -0
- data/doc/demo/test/fixtures/shared_index2s.yml +7 -0
- data/doc/demo/test/functional/admin/backend_controller_test.rb +35 -0
- data/doc/demo/test/functional/contents_controller_test.rb +81 -0
- data/doc/demo/test/functional/searches_controller_test.rb +71 -0
- data/doc/demo/test/smoke/drb_smoke_test.rb +321 -0
- data/doc/demo/test/smoke/process_stats.rb +21 -0
- data/doc/demo/test/test_helper.rb +30 -0
- data/doc/demo/test/unit/comment_test.rb +217 -0
- data/doc/demo/test/unit/content_test.rb +705 -0
- data/doc/demo/test/unit/ferret_result_test.rb +24 -0
- data/doc/demo/test/unit/multi_index_test.rb +329 -0
- data/doc/demo/test/unit/remote_index_test.rb +23 -0
- data/doc/demo/test/unit/shared_index1_test.rb +108 -0
- data/doc/demo/test/unit/shared_index2_test.rb +13 -0
- data/doc/demo/test/unit/sort_test.rb +21 -0
- data/doc/demo/test/unit/special_content_test.rb +25 -0
- data/doc/demo/vendor/plugins/will_paginate/LICENSE +18 -0
- data/doc/demo/vendor/plugins/will_paginate/README +108 -0
- data/doc/demo/vendor/plugins/will_paginate/Rakefile +23 -0
- data/doc/demo/vendor/plugins/will_paginate/init.rb +21 -0
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +45 -0
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +44 -0
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +159 -0
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +95 -0
- data/doc/demo/vendor/plugins/will_paginate/test/array_pagination_test.rb +23 -0
- data/doc/demo/vendor/plugins/will_paginate/test/boot.rb +27 -0
- data/doc/demo/vendor/plugins/will_paginate/test/console +10 -0
- data/doc/demo/vendor/plugins/will_paginate/test/finder_test.rb +219 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/admin.rb +3 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/companies.yml +24 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/company.rb +23 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developer.rb +11 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml +13 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/project.rb +4 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/projects.yml +7 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/replies.yml +20 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/reply.rb +5 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/schema.sql +44 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topic.rb +19 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topics.yml +30 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/user.rb +2 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/users.yml +35 -0
- data/doc/demo/vendor/plugins/will_paginate/test/helper.rb +42 -0
- data/doc/demo/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +64 -0
- data/doc/demo/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +10 -0
- data/doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb +136 -0
- data/doc/monit-example +22 -0
- data/init.rb +24 -0
- data/install.rb +18 -0
- data/lib/act_methods.rb +147 -0
- data/lib/acts_as_ferret.rb +593 -0
- data/lib/ar_mysql_auto_reconnect_patch.rb +41 -0
- data/lib/blank_slate.rb +54 -0
- data/lib/bulk_indexer.rb +56 -0
- data/lib/class_methods.rb +279 -0
- data/lib/ferret_extensions.rb +192 -0
- data/lib/ferret_find_methods.rb +142 -0
- data/lib/ferret_result.rb +58 -0
- data/lib/ferret_server.rb +238 -0
- data/lib/index.rb +99 -0
- data/lib/instance_methods.rb +172 -0
- data/lib/local_index.rb +202 -0
- data/lib/more_like_this.rb +217 -0
- data/lib/multi_index.rb +133 -0
- data/lib/rdig_adapter.rb +149 -0
- data/lib/remote_functions.rb +43 -0
- data/lib/remote_index.rb +54 -0
- data/lib/remote_multi_index.rb +20 -0
- data/lib/search_results.rb +50 -0
- data/lib/server_manager.rb +71 -0
- data/lib/unix_daemon.rb +86 -0
- data/lib/without_ar.rb +52 -0
- data/recipes/aaf_recipes.rb +116 -0
- data/script/ferret_daemon +94 -0
- data/script/ferret_server +12 -0
- data/script/ferret_service +178 -0
- data/tasks/ferret.rake +39 -0
- metadata +246 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 Kasper Weibel, Jens Kraemer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
= acts_as_ferret
|
2
|
+
|
3
|
+
This ActiveRecord mixin adds full text search capabilities to any Rails model.
|
4
|
+
|
5
|
+
It is heavily based on the original acts_as_ferret plugin done by
|
6
|
+
Kasper Weibel and a modified version done by Thomas Lockney, which
|
7
|
+
both can be found on http://ferret.davebalmain.com/trac/wiki/FerretOnRails
|
8
|
+
|
9
|
+
== Project Wiki and Issue tracker
|
10
|
+
|
11
|
+
http://wiki.github.com/jkraemer/acts_as_ferret/
|
12
|
+
http://j-k.lighthouseapp.com/projects/45560-acts-as-ferret
|
13
|
+
|
14
|
+
== Installation
|
15
|
+
|
16
|
+
Aaf is available as a gem (gem install acts_as_ferret), or via git from github.com.
|
17
|
+
Github also offers tarball downloads, check out
|
18
|
+
http://github.com/jkraemer/acts_as_ferret/tree/master .
|
19
|
+
|
20
|
+
=== Set up your Rails > 2.1 project to use the acts_as_ferret gem.
|
21
|
+
|
22
|
+
Add this to your project's config/environment.rb (inside the Rails::Initializer.run block):
|
23
|
+
|
24
|
+
<tt>
|
25
|
+
config.gem 'acts_as_ferret', :version => '~> 0.4.8'
|
26
|
+
config.after_initialize { ActsAsFerret::load_config }
|
27
|
+
config.to_prepare { ActsAsFerret::load_config }
|
28
|
+
</tt>
|
29
|
+
|
30
|
+
With the gem installed, change into your RAILS_ROOT and run the supplied aaf_install script.
|
31
|
+
This will copy rake tasks, capistrano recipes and the ferret server config and startup script
|
32
|
+
into your project.
|
33
|
+
|
34
|
+
In order to have the capistrano recipe loaded you'll have to patch your Capfile a bit. I use to have
|
35
|
+
a line like that in my Capfiles, loading everything found below RAILS_ROOT/lib/recipes:
|
36
|
+
|
37
|
+
<tt>Dir['lib/recipes/**/*.rb'].each { |plugin| load(plugin) }</tt>
|
38
|
+
|
39
|
+
|
40
|
+
=== Installation inside your Rails project via script/plugin
|
41
|
+
|
42
|
+
script/plugin install git://github.com/jkraemer/acts_as_ferret.git
|
43
|
+
|
44
|
+
No additional setup needed.
|
45
|
+
|
46
|
+
|
47
|
+
== Usage
|
48
|
+
|
49
|
+
There are two ways to make your models searchable with aaf. The option to configure acts_as_ferret with
|
50
|
+
a single configuration file has been introduced because it makes more sense when a single index holds multiple
|
51
|
+
models - it's simply more logicl to define that index and tell which models should go into it than to call
|
52
|
+
acts_as_ferret in each model pointing to the same index every time.
|
53
|
+
|
54
|
+
=== central configuration file
|
55
|
+
|
56
|
+
With this option, all acts_as_ferret indexes are configured in a single file, RAILS_ROOT/config/aaf.rb:
|
57
|
+
|
58
|
+
ActsAsFerret::define_index( 'my_index',
|
59
|
+
:models => {
|
60
|
+
SomeModel => {
|
61
|
+
:fields => {
|
62
|
+
:name => { :boost => 4, :store => :yes, :via => :ferret_title },
|
63
|
+
:foo => { :store => :no, :index => :untokenized },
|
64
|
+
:baz => { :store => :yes, :via => :ferret_content }
|
65
|
+
}
|
66
|
+
}
|
67
|
+
} )
|
68
|
+
|
69
|
+
ActsAsFerret::define_index( 'some_other_index',
|
70
|
+
:models => {
|
71
|
+
Foo => { :fields => { ... } },
|
72
|
+
Bar => { ... },
|
73
|
+
} )
|
74
|
+
|
75
|
+
|
76
|
+
As you can see for every index you want to define there's a single call, and each model that should go
|
77
|
+
into the index gets it's own ferret options hash (see the acts_as_ferret class method docs for all available options).
|
78
|
+
|
79
|
+
=== In your models (the old fashioned way)
|
80
|
+
include the following in your model class (specifiying the fields you want to get indexed):
|
81
|
+
|
82
|
+
<tt>acts_as_ferret :fields => [ :title, :description ]</tt>
|
83
|
+
|
84
|
+
now you can use ModelClass.find_with_ferret(query) to find instances of your model
|
85
|
+
whose indexed fields match a given query. All query terms are required by default,
|
86
|
+
but explicit OR queries are possible. This differs from the ferret default, but
|
87
|
+
imho is the more often needed/expected behaviour (more query terms result in
|
88
|
+
less results).
|
89
|
+
|
90
|
+
Please see ActsAsFerret::ActMethods#acts_as_ferret for more information.
|
91
|
+
|
92
|
+
== Known issues
|
93
|
+
|
94
|
+
aaf is not yet ready for Rails3. Feel free to submit patches!
|
95
|
+
|
96
|
+
== License
|
97
|
+
|
98
|
+
Released under the MIT license.
|
99
|
+
|
100
|
+
== Authors
|
101
|
+
|
102
|
+
* Kasper Weibel Nielsen-Refs (original author)
|
103
|
+
* Jens Kraemer <jk@jkraemer.net> (current maintainer)
|
104
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'watson-acts_as_ferret'
|
4
|
+
s.version = '0.4.8.2'
|
5
|
+
s.authors = ['Thomas Watson']
|
6
|
+
s.summary = 'acts_as_ferret - Ferret based full text search for any ActiveRecord model'
|
7
|
+
s.description = 'Rails plugin that adds powerful full text search capabilities to ActiveRecord models. This is a fork of the original acts_as_ferret plugin by Jens Kraemer with some minor custom ajustments.'
|
8
|
+
s.email = 'w@tson.dk'
|
9
|
+
s.homepage = 'http://github.com/watson/acts_as_ferret'
|
10
|
+
|
11
|
+
s.bindir = 'bin'
|
12
|
+
s.executables = ['aaf_install']
|
13
|
+
s.default_executable = 'aaf_install'
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
|
16
|
+
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.required_ruby_version = '>=1.8.6'
|
19
|
+
s.rubygems_version = '1.3.6'
|
20
|
+
if s.respond_to? :specification_version then
|
21
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
25
|
+
s.add_runtime_dependency('jk-ferret', [">= 0.11.8"])
|
26
|
+
else
|
27
|
+
s.add_dependency('jk-ferret', [">= 0.11.8"])
|
28
|
+
end
|
29
|
+
else
|
30
|
+
s.add_dependency('jk-ferret', [">= 0.11.8"])
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
s.has_rdoc = true
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.extra_rdoc_files = [
|
37
|
+
'LICENSE',
|
38
|
+
'README'
|
39
|
+
]
|
40
|
+
s.test_files = Dir['test/**/*rb']
|
41
|
+
s.files = [
|
42
|
+
'bin/*',
|
43
|
+
'config/*',
|
44
|
+
'doc/**/*',
|
45
|
+
'recipes/*',
|
46
|
+
'script/*',
|
47
|
+
'tasks/*',
|
48
|
+
'lib/**/*rb'
|
49
|
+
].map{|p| Dir[p]}.flatten +
|
50
|
+
[
|
51
|
+
'acts_as_ferret.gemspec',
|
52
|
+
'init.rb',
|
53
|
+
'install.rb',
|
54
|
+
'README',
|
55
|
+
'LICENSE',
|
56
|
+
]
|
57
|
+
|
58
|
+
end
|
data/bin/aaf_install
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# acts_as_ferret gem install script
|
3
|
+
# Use inside the root of your Rails project
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
@basedir = File.join(File.dirname(__FILE__), '..')
|
7
|
+
|
8
|
+
def install(src, target_dir, executable=false)
|
9
|
+
puts "Installing: #{src}"
|
10
|
+
src = File.join(@basedir, src)
|
11
|
+
fname = File.basename(src)
|
12
|
+
target = File.join(target_dir, fname)
|
13
|
+
if File.exists?(target)
|
14
|
+
puts "#{target} already exists, skipping"
|
15
|
+
else
|
16
|
+
FileUtils.mkdir_p target_dir
|
17
|
+
FileUtils.cp src, target
|
18
|
+
FileUtils.chmod 0755, target if executable
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
install 'script/ferret_server', 'script', true
|
24
|
+
install 'config/ferret_server.yml', 'config'
|
25
|
+
install 'tasks/ferret.rake', 'lib/tasks'
|
26
|
+
install 'recipes/aaf_recipes.rb', 'lib/recipes'
|
27
|
+
|
28
|
+
puts IO.read(File.join(@basedir, 'README'))
|
29
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# configuration for the acts_as_ferret DRb server
|
2
|
+
# host: where to reach the DRb server (used by application processes to contact the server)
|
3
|
+
# port: which port the server should listen on
|
4
|
+
# socket: where the DRb server should create the socket (absolute path), this setting overrides host:port configuration
|
5
|
+
# pid_file: location of the server's pid file (relative to RAILS_ROOT)
|
6
|
+
# log_file: log file (default: RAILS_ROOT/log/ferret_server.log
|
7
|
+
# log_level: log level for the server's logger
|
8
|
+
production:
|
9
|
+
host: localhost
|
10
|
+
port: 9010
|
11
|
+
pid_file: log/ferret.pid
|
12
|
+
log_file: log/ferret_server.log
|
13
|
+
log_level: warn
|
14
|
+
|
15
|
+
# aaf won't try to use the DRb server in environments that are not
|
16
|
+
# configured here.
|
17
|
+
#development:
|
18
|
+
# host: localhost
|
19
|
+
# port: 9010
|
20
|
+
# pid_file: log/ferret.pid
|
21
|
+
#test:
|
22
|
+
# host: localhost
|
23
|
+
# port: 9009
|
24
|
+
# pid_file: log/ferret.pid
|
data/doc/README.win32
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Credits
|
2
|
+
=======
|
3
|
+
|
4
|
+
The Win32 service support scripts have been written by
|
5
|
+
Herryanto Siatono <herryanto@pluitsolutions.com>.
|
6
|
+
|
7
|
+
See his accompanying blog posting at
|
8
|
+
http://www.pluitsolutions.com/2007/07/30/acts-as-ferret-drbserver-win32-service/
|
9
|
+
|
10
|
+
|
11
|
+
Usage
|
12
|
+
=====
|
13
|
+
|
14
|
+
There are two scripts:
|
15
|
+
|
16
|
+
script/ferret_service is used to install/remove/start/stop the win32 service.
|
17
|
+
|
18
|
+
script/ferret_daemon is to be called by Win32 service to start/stop the
|
19
|
+
DRbServer.
|
20
|
+
|
21
|
+
Run 'ruby script/ferret_service -h' for more info.
|
22
|
+
|
23
|
+
|
data/doc/demo/README
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
|
4
|
+
Rails is a web-application and persistence framework that includes everything
|
5
|
+
needed to create database-backed web-applications according to the
|
6
|
+
Model-View-Control pattern of separation. This pattern splits the view (also
|
7
|
+
called the presentation) into "dumb" templates that are primarily responsible
|
8
|
+
for inserting pre-built data in between HTML tags. The model contains the
|
9
|
+
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
10
|
+
the business logic and knows how to persist themselves to a database. The
|
11
|
+
controller handles the incoming requests (such as Save New Account, Update
|
12
|
+
Product, Show Post) by manipulating the model 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. Run the WEBrick servlet: <tt>ruby script/server</tt> (run with --help for options)
|
32
|
+
...or if you have lighttpd installed: <tt>ruby script/lighttpd</tt> (it's faster)
|
33
|
+
2. Go to http://localhost:3000/ and get "Congratulations, you've put Ruby on Rails!"
|
34
|
+
3. Follow the guidelines on the "Congratulations, you've put Ruby on Rails!" screen
|
35
|
+
|
36
|
+
|
37
|
+
== Example for Apache conf
|
38
|
+
|
39
|
+
<VirtualHost *:80>
|
40
|
+
ServerName rails
|
41
|
+
DocumentRoot /path/application/public/
|
42
|
+
ErrorLog /path/application/log/server.log
|
43
|
+
|
44
|
+
<Directory /path/application/public/>
|
45
|
+
Options ExecCGI FollowSymLinks
|
46
|
+
AllowOverride all
|
47
|
+
Allow from all
|
48
|
+
Order allow,deny
|
49
|
+
</Directory>
|
50
|
+
</VirtualHost>
|
51
|
+
|
52
|
+
NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
|
53
|
+
should be on and ".cgi" should respond. All requests from 127.0.0.1 go
|
54
|
+
through CGI, so no Apache restart is necessary for changes. All other requests
|
55
|
+
go through FCGI (or mod_ruby), which requires a restart to show changes.
|
56
|
+
|
57
|
+
|
58
|
+
== Debugging Rails
|
59
|
+
|
60
|
+
Have "tail -f" commands running on both the server.log, production.log, and
|
61
|
+
test.log files. Rails will automatically display debugging and runtime
|
62
|
+
information to these files. Debugging info will also be shown in the browser
|
63
|
+
on requests from 127.0.0.1.
|
64
|
+
|
65
|
+
|
66
|
+
== Breakpoints
|
67
|
+
|
68
|
+
Breakpoint support is available through the script/breakpointer client. This
|
69
|
+
means that you can break out of execution at any point in the code, investigate
|
70
|
+
and change the model, AND then resume execution! Example:
|
71
|
+
|
72
|
+
class WeblogController < ActionController::Base
|
73
|
+
def index
|
74
|
+
@posts = Post.find_all
|
75
|
+
breakpoint "Breaking out from the list"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
So the controller will accept the action, run the first line, then present you
|
80
|
+
with a IRB prompt in the breakpointer window. Here you can do things like:
|
81
|
+
|
82
|
+
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
83
|
+
|
84
|
+
>> @posts.inspect
|
85
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
86
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
87
|
+
>> @posts.first.title = "hello from a breakpoint"
|
88
|
+
=> "hello from a breakpoint"
|
89
|
+
|
90
|
+
...and even better is that you can examine how your runtime objects actually work:
|
91
|
+
|
92
|
+
>> f = @posts.first
|
93
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
94
|
+
>> f.
|
95
|
+
Display all 152 possibilities? (y or n)
|
96
|
+
|
97
|
+
Finally, when you're ready to resume execution, you press CTRL-D
|
98
|
+
|
99
|
+
|
100
|
+
== Console
|
101
|
+
|
102
|
+
You can interact with the domain model by starting the console through script/console.
|
103
|
+
Here you'll have all parts of the application configured, just like it is when the
|
104
|
+
application is running. You can inspect domain models, change values, and save to the
|
105
|
+
database. Starting the script without arguments will launch it in the development environment.
|
106
|
+
Passing an argument will specify a different environment, like <tt>console production</tt>.
|
107
|
+
|
108
|
+
|
109
|
+
== Description of contents
|
110
|
+
|
111
|
+
app
|
112
|
+
Holds all the code that's specific to this particular application.
|
113
|
+
|
114
|
+
app/controllers
|
115
|
+
Holds controllers that should be named like weblog_controller.rb for
|
116
|
+
automated URL mapping. All controllers should descend from
|
117
|
+
ActionController::Base.
|
118
|
+
|
119
|
+
app/models
|
120
|
+
Holds models that should be named like post.rb.
|
121
|
+
Most models will descend from ActiveRecord::Base.
|
122
|
+
|
123
|
+
app/views
|
124
|
+
Holds the template files for the view that should be named like
|
125
|
+
weblog/index.rhtml for the WeblogController#index action. All views use eRuby
|
126
|
+
syntax. This directory can also be used to keep stylesheets, images, and so on
|
127
|
+
that can be symlinked to public.
|
128
|
+
|
129
|
+
app/helpers
|
130
|
+
Holds view helpers that should be named like weblog_helper.rb.
|
131
|
+
|
132
|
+
config
|
133
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
134
|
+
|
135
|
+
components
|
136
|
+
Self-contained mini-applications that can bundle together controllers, models, and views.
|
137
|
+
|
138
|
+
lib
|
139
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
140
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
141
|
+
|
142
|
+
public
|
143
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
144
|
+
and javascripts. Also contains the dispatchers and the default HTML files.
|
145
|
+
|
146
|
+
script
|
147
|
+
Helper scripts for automation and generation.
|
148
|
+
|
149
|
+
test
|
150
|
+
Unit and functional tests along with fixtures.
|
151
|
+
|
152
|
+
vendor
|
153
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
154
|
+
This directory is in the load path.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Acts_as_Ferret demo project
|
2
|
+
===========================
|
3
|
+
|
4
|
+
This project is intended to run with edge rails which can
|
5
|
+
be installed with
|
6
|
+
|
7
|
+
rake rails:freeze:edge
|
8
|
+
|
9
|
+
|
10
|
+
You'll also need to set up a database for it.
|
11
|
+
SQL scripts for both SQLite and MySQL are provided in db/ .
|
12
|
+
|
13
|
+
Just set up one of these, and configure your db connection
|
14
|
+
in config/database.yml .
|
15
|
+
|
16
|
+
after that run
|
17
|
+
rake
|
18
|
+
to see the unit tests pass.
|
19
|
+
|
20
|
+
|
21
|
+
Please feel free to post bugs/enhancements/patches at
|
22
|
+
http://projects.jkraemer.net/acts_as_ferret .
|
23
|
+
|
data/doc/demo/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/switchtower.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
require 'tasks/rails'
|