Beware nested with_options clobbers!

kwerle May 18, 2012

Careful: with_options :foo => :bar do |something| something.with_options :foo => :baz do |inner| what_is(:foo) end end

:foo will be :baz. It will not be [:bar, :baz], for example.

This bit me when trying to do nested with_options for validation where both had :if => somethin...

Hidden Field Example

cantbecool May 7, 2012 1 thank

Here's a pseudo code example of a hidden field within an ERB template. A post has many comments and this comment form is in a post's show view. This would set a comment's post_id attribute.


<%= form_for(@comment) do |f| %>

<%= f.hidden_field :post_id, :value => @post.id %>

<% end %>


Dir

alanjcfs Apr 26, 2012

The documentation is using File.directory?("/path/to/directory"), but the method being referred to is Dir.exists?().

Dir.exists?(".")

=> true

The source code is the same as File.directory?().

BasicObject.new

botp Apr 24, 2012

Instantiates a new blank object (devoid of methods). The only class method of class BasicObject. see "ri BasicObject"

eg,

o=BasicObject.new (Object doesn't support #inspect) =>

o.methods NoMethodError: undefined method `methods' for #BasicObject:0x0000000267a0a0

def o.to_s self e...