Prev | Current Page 68 | Next

Brad Ediger

"Advanced Rails"

match(path))
params = parameter_shell.dup
params[:controller] = match[1].downcase if match[1]
params[:action] = match[2] || "index"
params[:id] = match[3] if match[3]
params
end
end
Further Reading | 45
The parameter_shell method returns the default set of parameters associated with
the route. This method body simply tests against the regular expression, populating
and returning the params hash if the regular expression matches. If there is no match,
the method returns nil.
Once this method body is created, it is evaluated in the context of the route using
instance_eval. This overwrites that particular route??™s recognize method.
Further Reading
Minero AOKI??™s Ruby Hacking Guide is an excellent introduction to Ruby??™s internals.
It is being translated into English at http://rhg.rubyforge.org/.
Eigenclass (http://eigenclass.org/) has several more technical articles on Ruby.
Evil.rb is a library for accessing the internals of Ruby objects. It can change objects??™
internal state, traverse and examine the klass and super pointers, change an
object??™s class, and cause general mayhem. Use with caution. It is available at http://
rubyforge.org/projects/evil/. Mauricio Fern??ndez gives a taste of Evil at http://eigenclass.
org/hiki.rb?evil.rb+dl+and+unfreeze.
Jamis Buck has a very detailed exploration of the Rails routing code, as well as several
other difficult parts of Rails, at http://weblog.


Pages:
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80