Example
Chops the last character off a string.
> a = "12345"
> a.chop
=> "1234"
> a
=> "12345"
> a.chop!
=> "1234"
> a
=> "1234
Community contributions, tips, and corrections to the documentation. (1708 notes)
Chops the last character off a string.
> a = "12345"
> a.chop
=> "1234"
> a
=> "12345"
> a.chop!
=> "1234"
> a
=> "1234
I notice other adapters use sql.sub!, not sql.gsub! and in fact I had trouble with adding the limit parameter to any query involving nested selects. Replacing sql.gsub! with sql.sub! solved that problem for me. Has anyone else had a similar experience with this method?
In other words, replace:...
If you need to track and log which before filters are called for the purpose of debugging your app/before_filters. Then here's a suggestion, how this could be accomplished:
Instead of the default text Email you can change it to "Primary Email" like this: f.label :email, "Primary Email"
in 3.0.5, the source code in line 15 looks like this: respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "unknown attribute: #{k}")
whats wrong with apidock?
Let's say you wanted to filter out passwords from:
s = "password=bob&password=jim&password=jane"
You'd do this:
r = /password\\=([^\\&]+)/
s.gsub!(r) { |m| m.gsub!($1, "[FILTERED]") }
Which would return
password=[FILTERED]&password=[FILTERED]&password=[FILTERED]
This isn't deprecated, it was just moved in Rails 3. See:
What's the recommended alternative to reload for more recent versions of Rails?
To test a string use match, e.g.
"test".should match("test")
Please note after filters are not executed when an exception occurs. You have to handle these situations explicitly.
When passing in an object, as opposed to a hash, you can't do this because url_for accepts one argument:
url_for(post, :only_path => true)
Instead, do this:
polymorphic_url(object, :routing_type => :path)
You can use this code to handle nested hashes and arrays. I'm not sure if it handles every case, and it could probably be refactored better, but it's working quite well for us.
require 'active_support/core_ext/hash'
def normalize_params(params, key=nil)
params = params.flatten_keys if...
Note that ActiveRecord will not update the timestamp fields (updated_at/updated_on) when using update_all().
In rails 3 these have been moved to ActiveModel::Validations::HelperMethods
at least not according to the Rails release notes: http://edgeguides.rubyonrails.org/3_0_release_notes.html#validations
If you want to find any number of records without sorting your entire table randomly every time, try the solution I posted here:
http://rubyglasses.blogspot.com/2010/05/activerecord-find-in-random-order.html
For Rails 3, see AbstractController::Callbacks::ClassMethods#skip_filter .
waves hand
You're probably looking for:
ActionView::Helpers::PrototypeHelper#form_remote_tag
Don't store a connection in a variable, because another thread might try to use it when it's already checked back in into the connection pool. See: ActiveRecord::ConnectionAdapters::ConnectionPool
connection = ActiveRecord::Base.connection
threads = (1..100).map do
Thread.new do...
I18n.l Time.now, :format => "%e %B"