Method moved in 2.1 and again in 3.0 (beta)
It was moved from and back to Module#alias_method_chain
Community contributions, tips, and corrections to the documentation. (1708 notes)
It was moved from and back to Module#alias_method_chain
@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...
Locale en: number_with_precision(111.2345) # => 111.235
Locale fr-FR: number_with_precision(111.2345) # => 111,235
Same with delimiter.
As far as I can tell, at least on a migration of a column from an integer to a decimal, this does not get rid of existing data.
Rails versions as of 2.1.0 have basic timezone support built-in to the Time object. However, to get a list of all the timezones you need to install the tzinfo gem.
All contries, all timezones: TZInfo::Country.all.sort_by { |c| c.name }.each do |c| puts c.name #...
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.
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...
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 you need to process both key and value of the Hash:
>> {"a" => "aa", "b" => "bb", "c" => "cc"}.collect {|k,v| [k,k+v]}
=> [["a", "aaa"], ["b", "bbb"], ["c", "ccc"]]
Helper generates a div element with a hidden input inside. This is a security feature of Rails called cross-site request forgery protection and f...
If you pass something like this: http.set_form_data({:a => {:b => :c}}) it will completely mangle the value. So don't use it.
From CgiRequest you can get the client ip in controller:
request.remote_ip
You can access controller attributes from views via the @controller variable.
It has some important attributes:
def rescue_action_in_public(exception)
case exception
when ActiveRecord::RecordNotFound, ActionController::UnknownAction, ActionController::RoutingError
redirect_to errors_path(404), :status=>301
else
redirect_to errors_path(500)
end
end
You can list multiple attributes if they share the same validations
validates :title, :body, :presence => true
sending the attributes as an array will return an error
validates [:title, :body], :presence => true
#=> ArgumentError: Attribute names must be symbols
Seems when you change key directly it doesn't update association automatically. >> chicken = Chicken.first >> chicken.head => old_head >> chicken.head_id = new_head.id >> chicken.head => old_head
Easy (stupid?) way to fix it:
class Chicken
def head_id=(value)...
I was surprised to find that the local file is opened and written even if you pass the block. If you're local working directory isn't writeable or doesn't have the space, you're out of luck.
I was surprised to find that the local file is opened and written even if you pass the block. If you're local working directory isn't writeable or doesn't have the space, you're out of luck.
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
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...