Flowdock

Notes posted by ssoroka

RSS feed
March 27, 2013 - (v3.0.0 - v3.2.13)
0 thanks
November 11, 2011
3 thanks

Catching and throwing -- don't!

@wiseleyb and @glosakti, neither of your suggestions are necessary, and both are bad practices.

This test:

test "transactions" do
  assert_raises ZeroDivisionError do
    User.transaction do
      1/0
    end
  end
end

passes just fine on its own, with the transaction rolled back as you’d expect. No need to hack something ugly together.

September 13, 2011
0 thanks

more options

useful options are:

:root => ‘object’, :skip_instruct => true, :indent => 2

:builder can also be used to pass your own Builder::XmlMarkup instance.

July 27, 2011
1 thank

includes request parameters

fullpath includes request parameters in the result

June 22, 2011
1 thank

:url conflicts with :format

If you are passing both :url and :format, url overwrites the use of format, so you’ll need to pass it in the url like so:

form_for user, :url => user_path(@user, :format => :json)
June 17, 2011
0 thanks

don't forget :root

You can rename the root tag if you don’t like what is being generated.

line_item.to_xml(:skip_instruct => true, :root => 'line-item')
October 22, 2010
1 thank

doesn't work directly off a class.

for some reason this method only works on relation objects, not directly on an AR class.

# doesn't work
User.offset(3).limit(1)

# does work
User.limit(1).offset(3)

there’s an closed ticket for this here http://rails.lighthouseapp.com/projects/8994/tickets/5688-modeloffsetxlimitx-unknown-offset-method-exception and should be resolved in the next release of rails.

October 22, 2010
1 thank

still broken

add_index is a different method. I think this is just a bug and it’s broken.

October 20, 2010
7 thanks

use raw() instead

Don’t use this method unless you’re sure your string isn’t nil. Instead use the raw() method, which wont raise an exception on nil.

October 16, 2010 - (>= v3.0.0)
12 thanks

needs to be paired with respond_to

Needs to be paired with respond_to at the top of your class.

class MyController < ApplicationController
  respond_to :js, :html
September 9, 2010
2 thanks

bad idea.

Just a note, ypetya’s idea of using a before filter to set the primary key wont scale. transactions will eventually step on each other and probably end up with duplicate key ids, unless you have some other method to ensure uniqueness.

You’d be better off using mysql to generate the default integer primary key and have a secondary string “key” field.

September 9, 2010
0 thanks

Doesn't work? Don't think it ever has.

This doesn’t work for me. I do something like:

create_table :user_follows, :force => true do |t|
  t.references :user
  t.references :followed_user
  t.timestamps
  t.index :user
  t.index :followed_user
end

and I get:

rake aborted!
An error has occurred, all later migrations canceled:

undefined method `index' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x106c02220>

add_index has the same effect.