[ANN] Rails 0.7.0, Action Pack 0.8.5, Active Record 0.9.5

  • Thread starter David Heinemeier Hansson
  • Start date
D

David Heinemeier Hansson

I gather that most people are now familar with the RoR suite, so I'm
skipping the formal introductions and will just bring you the meat.

Get it all from http://www.rubyonrails.org, talk it up on #rubyonrails
(FreeNet).

Or even easier, just do "gem install rails" (or "gem update" if you're
already running on Gem Rails) -- you'll automatically install all the
newest versions of the required dependencies.

Rails 0.7.0: Fixed WEBrick, new_model generator, easier fixtures
================================================================

The WEBrick dispatch has been cured of its static file illnesses,
there’s a new_model generator that handles camel case models
gracefully, and fixtures are easier than ever to create. Also a few
other minor fixes and of course the inclusion of AP 0.8.5 and AR 0.9.5.

* Added an optional second argument to the new_model script that allows
the programmer to specify the table name, which will used to generate a
custom table_name method in the model and will also be used in the
creation of fixtures. [Kevin Radloff]

* script/new_model now turns AccountHolder into account_holder instead
of accountholder [Kevin Radloff]

* Fixed the faulty handleing of static files with WEBrick [Andreas
Schwarz]

* Unified function_test_helper and unit_test_helper into test_helper

* Fixed bug with the automated production => test database dropping on
PostgreSQL [dhawkins]

* create_fixtures in both the functional and unit test helper now turns
off the log during fixture generation and can generate more than one
fixture at a time. Which makes it possible for assignments like:

@people, @projects, @project_access, @companies, @accounts =
create_fixtures "people", "projects", "project_access",
"companies", "accounts"

* Upgraded to Action Pack 0.8.5 (locally-scoped variables, partials,
advanced send_file)

* Upgraded to Active Record 0.9.5 (better table_name guessing, cloning,
find_all_in_collection)


Action Pack 0.8.5: Local template variables, partials, better send_file
=======================================================================

Another major upgrade that adds the ability to pass locally-scoped
variables between templates, use the brand new partials approach to
simplify iteration over many objects with their own template, and a
much improved send_file method. This release also includes a bunch of
smaller tweaks and fixes.

* Introduced passing of locally scoped variables between templates:

You can pass local variables to sub templates by using a hash of
with the variable
names as keys and the objects as values:

<%= render "shared/header", { "headline" => "Welcome", "person"
=> person } %>

These can now be accessed in shared/header with:

Headline: <%= headline %>
First name: <%= person.first_name %>

* Introduced the concept of partials as a certain type of sub templates:

There's also a convenience method for rendering sub templates
within the current
controller that depends on a single object (we call this kind of
sub templates for
partials). It relies on the fact that partials should follow the
naming convention
of being prefixed with an underscore -- as to separate them from
regular templates
that could be rendered on their own. In the template for
Advertiser#buy, we could have:

<% for ad in @advertisements %>
<%= render_partial "ad", ad %>
<% end %>

This would render "advertiser/_ad.rhtml" and pass the local
variable +ad+
for the template to display.

== Rendering a collection of partials

The example of partial use describes a familar pattern where a
template needs
to iterate over a array and render a sub template for each of the
elements.
This pattern has been implemented as a single method that accepts
an array and
renders a partial by the same name of as the elements contained
within. So the
three-lined example in "Using partials" can be rewritten with a
single line:

<%= render_collection_of_partials "ad", @advertisements %>

So this will render "advertiser/_ad.rhtml" and pass the local
variable +ad+ for
the template to display.

* Improved send_file by allowing a wide range of options to be applied
[Jeremy Kemper]:

Sends the file by streaming it 4096 bytes at a time. This way the
whole file doesn't need to be read into memory at once. This makes
it feasible to send even large files.

Be careful to sanitize the path parameter if it coming from a web
page. send_file(@params['path'] allows a malicious user to
download any file on your server.

Options:
* <tt>:filename</tt> - specifies the filename the browser will see.
Defaults to File.basename(path).
* <tt>:type</tt> - specifies an HTTP content type.
Defaults to 'application/octet-stream'.
* <tt>:disposition</tt> - specifies whether the file will be shown
inline or downloaded.
Valid values are 'inline' and 'attachment' (default).
* <tt>:buffer_size</tt> - specifies size (in bytes) of the buffer
used to stream
the file. Defaults to 4096.

The default Content-Type and Content-Disposition headers are
set to download arbitrary binary files in as many browsers as
possible. IE versions 4, 5, 5.5, and 6 are all known to have
a variety of quirks (especially when downloading over SSL).

Simple download:
send_file '/path/to.zip'

Show a JPEG in browser:
send_file '/path/to.jpeg', :type => 'image/jpeg', :disposition =>
'inline'

Read about the other Content-* HTTP headers if you'd like to
provide the user with more information (such as
Content-Description).
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11

Also be aware that the document may be cached by proxies and
browsers.
The Pragma and Cache-Control headers declare how the file may be
cached
by intermediaries. They default to require clients to validate with
the server before releasing cached responses. See
http://www.mnot.net/cache_docs/ for an overview of web caching and
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
for the Cache-Control header spec.

* Added pluralize method to the TextHelper that makes it easy to get
strings like "1 message", "3 messages"

* Added proper escaping for the rescues [Andreas Schwartz]

* Added proper escaping for the option and collection tags [Andreas
Schwartz]

* Fixed NaN errors on benchmarking [Jim Weirich]

* Fixed query string parsing for URLs that use the escaped versions of
& or ; as part of a key or value

* Fixed bug with custom Content-Type headers being in addition to
rather than instead of the default header. (This bug didn't matter with
neither CGI or mod_ruby, but FCGI exploded on it) [With help from Ara
T. Howard]


Active Record 0.9.5: Better table_names, cloning, find_all_in_collection
========================================================================

The table name guessing just got a brain upgrade that enables it to
guess correctly in far more cases than the old once: Child will look
for children, Wife for wives, and more. It’s now also possible to clone
an Active Record safely and we’ve added another method to the has_many
macro for finding within the collection. Lots of smaller fixes as well.

* Expanded the table_name guessing rules immensely [Florian Green].
Documentation:

Guesses the table name (in forced lower-case) based on the name of
the class in the inheritance hierarchy descending directly from
ActiveRecord. So if the hierarchy looks like: Reply < Message <
ActiveRecord, then Message is used to guess the table name from even
when called on Reply. The guessing rules are as follows:

* Class name ends in "x", "ch" or "ss": "es" is appended,
so a Search class becomes a searches table.
* Class name ends in "y" preceded by a consonant or "qu": The "y"
is replaced with "ies",
so a Category class becomes a categories table.
* Class name ends in "fe": The "fe" is replaced with "ves",
so a Wife class becomes a wives table.
* Class name ends in "lf" or "rf": The "f" is replaced with "ves",
so a Half class becomes a halves table.
* Class name ends in "person": The "person" is replaced with
"people",
so a Salesperson class becomes a salespeople table.
* Class name ends in "man": The "man" is replaced with "men",
so a Spokesman class becomes a spokesmen table.
* Class name ends in "sis": The "i" is replaced with an "e",
so a Basis class becomes a bases table.
* Class name ends in "tum" or "ium": The "um" is replaced with an
"a",
so a Datum class becomes a data table.
* Class name ends in "child": The "child" is replaced with
"children",
so a NodeChild class becomes a node_children table.
* Class name ends in an "s": No additional characters are added or
removed.
* Class name doesn't end in "s": An "s" is appended,
so a Comment class becomes a comments table.
* Class name with word compositions: Compositions are underscored,
so CreditCard class becomes a credit_cards table.

Additionally, the class-level table_name_prefix is prepended to the
table_name and the table_name_suffix is appended.
So if you have "myapp_" as a prefix, the table name guess for an
Account class becomes "myapp_accounts".

You can also overwrite this class method to allow for unguessable
links, such as a Mouse class with a link to a "mice" table. Example:

class Mouse < ActiveRecord::Base
def self.table_name() "mice" end
end

This conversion is now done through an external class called
Inflector residing in lib/active_record/support/inflector.rb.

* Added find_all_in_collection to has_many defined collections. Works
like this:

class Firm < ActiveRecord::Base
has_many :clients
end

firm.id # => 1
firm.find_all_in_clients "revenue > 1000" # SELECT * FROM clients
WHERE firm_id = 1 AND revenue > 1000

[Requested by Dave Thomas]

* Fixed finders for inheritance hierarchies deeper than one level
[Florian Weber]

* Added add_on_boundry_breaking to errors to accompany add_on_empty as
a default validation method. It's used like this:

class Person < ActiveRecord::Base
protected
def validation
errors.add_on_boundry_breaking "password", 3..20
end
end

This will add an error to the tune of "is too short (min is 3
characters)" or "is too long (max is 20 characters)" if the password is
outside the boundry. The messages can be changed by passing a third and
forth parameter as message strings.

* Implemented a clone method that works properly with AR. It returns a
clone of the record that hasn't been assigned an id yet and is treated
as a new record.

* Allow for domain sockets in PostgreSQL by not assuming localhost when
no host is specified [Scott Barron]

* Fixed that bignums are saved properly instead of attempted to be
YAMLized [Andreas Schwartz]

* Fixed a bug in the GEM where the rdoc options weren't being passed
according to spec [Chad Fowler]

* Fixed a bug with the exclusively_dependent option for has_many

--
David Heinemeier Hansson,
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://www.instiki.org/ -- A No-Step-Three Wiki in Ruby
http://www.basecamphq.com/ -- Web-based Project Management
http://www.loudthinking.com/ -- Broadcasting Brain
http://www.nextangle.com/ -- Development & Consulting Services
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top