Re: IE GOTCHA

Mange Jul 10, 2010 2 thanks

@insane-dreamer

That has nothing to do with IE. When you specify +:cache+ => +true+ you are saying that the files referenced should be saved to a file called +all.js+. When the script encounters the next line, it will overwrite the same file with the new contents.

Caching is not compressing, it do...

Common use

lukewendling Jul 3, 2010 4 thanks

I typically use require_dependency when developing a class or module that resides in my rails app, perhaps in the lib/ dir. A normal require statement does not reload my changes, so I use require_dependency in files that reference my newly developed class or module.

Takes array

eric_programmer Jul 2, 2010

Like assert_difference this method can take an array of expressions to evaluate all of them. For example:

assert_no_difference ['Publisher.count', 'User.count', 'Membership.count'] do post :create end

It creates an assertion for each item in the array. So this will add three assertions to you...

can return nil

ColinDKelley Jun 25, 2010

I was surprised to get nil back when the right hand side (RHS) was nil. (I was expecting an exception.)

>> "abc" <=> nil
=> nil

Looking at the source I find you'll get nil back in several cases when the RHS isn't a string.

  • If the RHS doesn't implement to_str.
  • If the RHS doesn't imple...

Accessing controller data

ypetya Jun 23, 2010 2 thanks

You can access controller attributes from views via the @controller variable.

It has some important attributes:

  • @controller.controller_name -> the name of the controller
  • @controller.request -> returns the ActionController::Request
    • @controller.request.method -> the request method ( get, p...

Add requires!

wiseleyb Jun 13, 2010

Useful for methods that take options = {}

class Hash

def requires!(*params)
params.each do |param| 
  raise ArgumentError.new("Missing required parameter: #{param}") unless self.has_key?(param) 
end
end

end

keys to/from symbols

wiseleyb Jun 13, 2010

There's probably a more effecient way to do this...

class Hash

def keys_to_strings
res = {}
self.keys.each do |k|
  if self[k].is_a?(Hash)
    res[k.to_s] = self[k].keys_to_strings
  else
    res[k.to_s] = self[k]
  end
end
return res
end

def...