Was removed to a plugin in v 2.0
Is now the auto_complete plugin here:
Community contributions, tips, and corrections to the documentation. (1708 notes)
Is now the auto_complete plugin here:
beware, update_all silently ignores :limit and :order option in 3.0.8.
I've fixed my code temporarily with
update_all "foo=1 where #{myscope.where_values} limit 1"
The trick to getting the helper to populate a unique HTML ID and for rails to recognise a collection is to give the helper a unique 'name' and to set the :name symbol to parameter with an array symbol '[]'.
<% Cars.each do |c| %>
<%= check_box_tag "car_ids[#{c.id}]", c.id, :name => "car_ids...
My 5 cents.
I find trully useful this. Is a kind of generalized zip. You can combine 2 or more enumerables (arrays or others) of any size into a hash, array of arrays, .... The size of the result is the size of the bigest of the enumerables. For the shortests enumerables nil elements are used at t...
Iphone example should be def self.matches?(request)
if you want to find without default scopes in rails 3 and with_exclusive_scope is giving you protected method errors in controllers, use unscoped for a similar purpose
In response to wiseleyb, I don't believe that you could put "rescue" in a transaction block, let alone catching ActiveRecord::Rollback. It would lead you to an "unexpected kRESCUE" error.
I think this is more appropriate.
def start_transaction
Company.transaction do
# don't forget t...
>> a = [1,2,3]
>> a.sample
2
the same as
>> a[rand(a.length - 1)]
1
I thought using to_formatted_s(:db) on an array of ids would separate them with commas in a nice way. Wrong. It does, but it also changes the numbers. === Wrong [60, 271, 280, 283].to_formatted_s(:db) # => "121,543,561,567" # Completely different numbers!
Instead, use the join...
A little gotcha I ran into.
This must be defined before you define your relationships.
ie: class Ticket < ActiveRecord::Base set_table_name 'ticket' belongs_to :customer has_one :account, :through => :customer end
if you do the relationships first it will not use the correct t...
At least in 3.0.5, some of the previous examples no longer work: ActionView seems to quietly ignore Array content.
If you were using code of the form
content_tag(:li, nil, :class => 'someClass') {
arr.collect { |x|
content_tag(:ul, x)
}
}
it now needs to look like
conte...
Rails 3.0 does this with scope in config/routes.rb
scope "/exampleapp" do resources :examples root :to => "examples#index" end
--setup_mailer.rb in config/initializers --rails g mailer MailerName --methods in mailer_name.rb --files in views/mailer_name --MailerName.method(@object).deliver in object controller
-rails new ProjectName -switch directories -git repo "git init", then commit -add gems, bundle install -rails g scaffold TableName attribute:type attribute:type….. -authentication -add attribute_accessible/relationships/validations -get rid of index.html in public, set root "table#index" -rails g ni...
Below is a backport of the Ruby 1.9 implementation (minus some encoding stuff). The main thing this provides you is the ability to say :foo => ['bar', 'baz'] and have that turn into foo=bar&foo=baz (i.e. multiple values for the same key).
Just require into your project and use it like you are on 1....
Input strings are treated as regexp, but you can escape special regexp characters as usual:
"test".should match "\\test\\" #=> pass "test".should match '\test\' #=> pass "test".should match /\test\/ #=> pass
To remove a non empty directory use FileUtils:
Dir.mkdir("test_dir") Dir.mkdir("test_dir/sub_dir") FileUtils.remove_dir("test_dir",true)
Input String is treated as Regexp:
"*test*".should match "*test*" #=> fail
"*test*".should match ".*test.*" #=> pass
Regexp special characters inside input String can't [be] escaped:
"test".should match "\test\" #=> fail "test".should match /\test\/ #=> pass
Use eql to compare values as you would use ==:
"test".should eql "test" #=> pass
"test".should == "test" #=> pass
Do not confuse with equal which compares objects.
Equal fails when comparing two different string objects:
"test".should equal "test" #=> fail "test".should match "test" #=> pass "test".should eql "test" #=> pass
In fact:
"test".object_id.should_not eql "test".object_id #=> pass
Match fails when the string contains regex special characte...