Rails Core Weekly July 16 - August 6

Rails Core Weekly July 16 - August 6

Rails Core Weekly summarizes the rails-core mailing list, a list
dedicated to Ruby on Rails internals and its development. RCW is
brought to you by Rodney R. and proofread by the good people of
The Caboose (http://blog.caboo.se/) for accuracy.

RSS feed and RCW home:

http://www.pinupgeek.com/articles/category/rails-core-weekly-news

The ruby on rails podcast by Michael G. supposedly now includes
RCW:

http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=163609703&s=143452

==PLUG==

Caboose (spec. Court3nay) has started an Rails documentation projecct
to fund someone to improve the Rails API documentation.The initial
goal of 5000 USD has already been reached but you can still
participate especially if you are currently making your living with
Rails programming. Head on down to:

http://www.caboo.se/articles/2006/08/04/the-caboose-rails-documentation-project

Here are some the more interesting threads of the last 21 days or so.

[ thread: http://www.ruby-forum.com/topic/73013 ]

Zach D. is optimizing AR. In Zach’s words:

“My main focus is getting AR to better handle inserts, updates and
merges when working large sets of data. It can improve improve
performance by 400% to 600% in preliminary benchmarks.”

The code that does that is here:

http://blogs.mktec.com/zdennis/files/active_record_optimizations-0.0.1.tgz

If you’re interested in making things fly on mysql this is one thread
you should definitely check out.

[ http://www.ruby-forum.com/topic/73899#new ]

Shanti B. is looking for a better solution the form_tag_remote
with multipart file uploads. Ezra Z. recommends
http://sean.treadway.info/svn/plugins/responds_to_parent/README which
Chris MacGrath agrees works well.

[ thread: http://www.ruby-forum.com/topic/74071#new ]

Andrew K. needs a way for plugins to play nice together. Ciao
Chassot has a wonderful solution that uses the equally wonderful
alias_method_chain. Be sure to check out his example.

[ thread: http://www.ruby-forum.com/topic/74582#new ]

Stephen Blackstone submits a patch that allows for databases to be
defined in connection pools. You would write the usual connectiont to
database.yml but then add

development_read_pool: db1, db2, db3
development_write_pool: db1, db2, db3

A connection from the pool is then chosen using a round-robin scheme.
Stephen does a superb job explaining his patch. Must-read thread.

[thread: http://www.ruby-forum.com/topic/73617#new ]

Bob S. uncoveres the following curiosity when looking at AR dates:

“Right now, if you shove a date like: 07/18/06 to Rails, MySQL will
get 0006-07-16, but ParseDate.parsedate(‘07/18/06’, true) will create
the right 4-digit year.”

Jonathan V. has a plugin that fixes this but Bob is still
interested in people opinion on this issue. Shouldn’t Rails also work
without the date helpers ?

[thread: http://www.ruby-forum.com/topic/74822#new ]

Jonathan V. wonders why has_one objects are re-saved when the
parent is saved. He demonstrates this behaviour and provides a patch
to fix this:

class Person < ActiveRecord::Base
has_one :user
end

class User < ActiveRecord::Base
belongs_to :person
end

p = Person.find(:first)
p.save # As expected, nothing happens with the user association
p.user # Loads the associated object
p.save # As well as saving the person, the user is saved as well.
Seems unnecessary.

If you’re interested in dirty field checking, concurrency etc this is
a very interesting thread to read. Turns out Jeremy K. at one
point implemented dirty column tracking and Jamis did it on the object
level. Also Jonathan seems to have written yet another plugin to make
things work(acts_as_modified).

[thread: http://www.ruby-forum.com/topic/75313#new ]

Caio C. poses the question:

“Do you really think it’s a good idea to run filters more than once?”

Besides from being able to use skip_* this thread discusses the ins
and outs as well as performance benchmarks and the possibility of
adding a uniq option to the filter chain.

[thread: http://www.ruby-forum.com/topic/75353#new ]

Rick O. breaks the news that Simply Restful is now an integral part
of core with some slight syntax changes:

map.resource :comment, :path_prefix => ‘/posts/:post_id’
map.resource :user
map.resource :post

becomes

map.resources :comments, :path_prefix => ‘/posts/:post_id’
map.resources :users, :posts

[thread: http://www.ruby-forum.com/topic/75356#new ]

There seems to be some problem with the new map.resources code though.
Discussing the problem leads to a discussion about postbacks and REST.
Josh S. then coins the term “syntactic vinegar” in reference to
the syntax proposed by DHH. But DHH actually likes syntactic vinegar:

“I think syntactic vinegar is one of the best ways to encourage people
to do the right thing.”

Another must-read thread.

[thread: http://www.ruby-forum.com/topic/74111#new ]

Daniel is wondering if :dependent would be a good idea in case an
object has_many relations to not allow the parent to be destroyed if
it has children. Daniel tries a patch and gets some great advise from
Jeremy when Daniel runs into trouble when the order of his new
restrict association turns out to be significant. Jeremy:

“You can wrap the destroy method to leapfrog the callback chain.”

associations.rb, configure_dependency_*

case reflection.options[:dependent]
when :restrict
class_eval <<-end_eval
def destroy_with_has_many_#{reflection.name}
unless #{reflection.name}.blank?
raise DestroyRestricted.new(self,
#{reflection.name.inspect})
end
end

     alias_method_chain :destroy, "has_many_#{reflection.name}"
   end_eval
 # ...

end

base.rb

module ActiveRecord
class DestroyRestricted < ActiveRecordError
def initialize(model, by)
super “#{model.class.name} #{model.id} destroy restricted by
#{by}”
end
end
end

[thread: http://www.ruby-forum.com/topic/75349#new ]

Courtnay runs Rails with ruby 1.8.5 and comes across several issues
which he of course patches.
A rather funny thread about formatting ensues. What a single
semi-colon can do !

[thread: http://www.ruby-forum.com/topic/74568#new ]

Michael K. comes up with plan how to start weeding out the
soon-to-be unsupported and deprecated ways of doing things.
http://dev.rubyonrails.org/changeset/4623 offers a programmatic way of
doing that with the deprecate() method/

[thread: http://www.ruby-forum.com/topic/75496#new ]

Michael Schoen uncovers a performance issue with has_one associations
and caching. DHH asks to PDI.

[thread: http://www.ruby-forum.com/topic/75664#new ]

Lars P. give acts_as_nested_set some love i.e the ability to move a
node within a tree. Courtnay then asks whether aans shouldn’t move to
a plugin. Dave T. pitches in and says he still can’t make aans
work for some of his book examples. DHH seconds that aans is among the
thing to move out of core.
Others on that list includes all the Ajax macros (in_place_editor
etc), pagination, and possibly acts_as_list/acts_as_tree.

[thread: http://www.ruby-forum.com/topic/76042#new ]

The great Blake W. has been using the sql “having” clause a lot
and decided to extend AR to have :having option. Jeremy K. seems
to like this idea provides feedback and some pointers. Blake also
contemplates scoping to go with :having.

[thread: http://www.ruby-forum.com/topic/76109#new ]

Chris A. suggests nested controllers might be useful but is not sure
about how RESTful that would be.
DHH suggests nesting is most certainly on the todo list. Jamis B.
suggests:

map.resources :whatever_the_resources_are, :controller =>
“folder/controller”

might do the trick for now.

That it for, more soon.


Rodney
http://www.pinupgeek.com
http://www.dutchrailers.org

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs