How to return an empty ActiveRecord relation?
There is a now a “correct” mechanism in Rails 4: >> Model.none => #<ActiveRecord::Relation []>
There is a now a “correct” mechanism in Rails 4: >> Model.none => #<ActiveRecord::Relation []>
For RVM & OSX users Make sure you use latest rvm: rvm get stable Then you can do two things: Update certificates: rvm osx-ssl-certs update all Update rubygems: rvm rubygems latest For non RVM users Find path for certificate: cert_file=$(ruby -ropenssl -e ‘puts OpenSSL::X509::DEFAULT_CERT_FILE’) Generate certificate: security find-certificate -a -p /Library/Keychains/System.keychain > “$cert_file” security find-certificate … Read more
Maybe this is what you’re looking for? string = “line #1″\ “line #2″\ “line #3” p string # => “line #1line #2line #3”
Rack as Design Rack middleware is more than “a way to filter a request and response” – it’s an implementation of the pipeline design pattern for web servers using Rack. It very cleanly separates out the different stages of processing a request – separation of concerns being a key goal of all well designed software … Read more
By default Rails assumes that you have your files precompiled in the production environment, if you want use live compiling (compile your assets during runtime) in production you must set the config.assets.compile to true. # config/environments/production.rb … config.assets.compile = true … You can use this option to fallback to Sprockets when you are using precompiled … Read more
I ran into a similar problem when trying to use the JQuery generator for Rails 3 I solved it like this: Get the CURL Certificate Authority (CA) bundle. You can do this with: sudo port install curl-ca-bundle [if you are using MacPorts] or just pull it down directly wget http://curl.haxx.se/ca/cacert.pem Execute the ruby code that … Read more
A member route will require an ID, because it acts on a member. A collection route doesn’t because it acts on a collection of objects. Preview is an example of a member route, because it acts on (and displays) a single object. Search is an example of a collection route, because it acts on (and … Read more
Assuming fairly recent version of Rails you can always run: rake db:migrate:up VERSION=20090408054532 Where version is the timestamp in the filename of the migration. Edit: At some point over the last 8 years (I’m not sure what version) Rails added checks that prevent this from running if it has already been run. This is indicated … Read more
Use .drop(1). This has the benefit of returning a new Array with the first element removed, as opposed to using .shift, which returns the removed element, not the Array with the first element removed. NOTE: It does not affect/mutate the original Array. a = [0,1,2,3] a.drop(1) # => [1, 2, 3] a # => [0,1,2,3] … Read more
To turn it off: old_logger = ActiveRecord::Base.logger ActiveRecord::Base.logger = nil To turn it back on: ActiveRecord::Base.logger = old_logger