Today I learned that Ruby on Rails has shipped with a built-in slug generator since Rails 2.2: > "What Up Dog".parameterize => "what-up-dog" > "foo/bar".parameterize => "foo-bar"
...revert to the original Rubygems by saying gem uninstall slimgems #If you are using Rails 2.3.11 Rails 2.3.11 can also trigger this warning. Install 2.3.12+. After installation, you need to...
JavaScripts and CSS should be minified for production use. In Rails 3.1+ the asset pipeline will take care of this. Thus you're best off using an uncompressed version of...
...be easier and you will still get all the minification love once deployed. In Rails 2.3 and 3.0 you should at least embed external JavaScript libraries in minified form, using...
...see below) -- but can be a problem, for example for the capture method of Rails. Consider these methods: def stuff puts 'yielding...' yield puts 'yielded.' true end
...have probably seen it before, e.g. a return in an each block. Impact on Rails applications Since this is something that you would have to do yourself, you could just...
In Rails 2, when calling instance_eval or instance_exec on a scope, the scope will fetch its records from the database. This has been fixed in Rails...
...for session hashes. Use update instead. Outline Let's assume you're modifying the Rails session. For simplicity, let's also assume your session is empty when you start (same...
...is the ActionController::Session::AbstractStore::SessionHash class (session is of that type in your Rails application, but also in Rack middleware): class SessionHash < Hash # ... def update(hash) load_for_write...
Warnings like those below may originate from rspec or shoulda-matchers or other gems that have not updated yet to...
Rails 2.3.16+ on Ruby 1.9 causes warnings like this: .../gems/activesupport-2.3.17/lib/active_support/core_ext/string/output_safety.rb:22: warning: regexp match /.../n against to UTF-8 string Many thanks to grosser for supplying a monkey-patch for...
...Rails 2.3 (Commit f93e3f0ec3 fixed it for Rails 3). Just put it into config/initializers/ to make those warnings go away. Since we're using RSpec on most projects, I've...
Simply give the select helper an option :disabled, passing either a single value or an array. You need to specify...
...root_url, :data => { :foo => 'bar', :bam => 'baz' } This will produce: Label Only works in Rails 3. In Rails 2 you do = link_to 'Label', root_url, 'data-foo' => 'bar', 'data...
We're adding a script console-for to open a remote Rails console with one command. Also have a look at shell-for, which this script is relying on.
Ever wondered if there is a reverse for Rails' .each(&:to_s) idiom? Turns out there is... You probably already know, that you can abbreviate code like dogs.each { |dog| dog.bark...
If you want to inspect the compiled code of your erb (or haml) templates, you can run the following code...
...PostgreSQL data types to ActiveRecord and convenient querying extensions for ActiveRecord and Arel for Rails 4.x Common table expressions Relation#with Model.from_cte Arrays Face.where.contains tags: %w[happy smiling...
...prevent this, test for the right environment and place the JS-code afterwards: - if Rails.env.production? :javascript var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); _gaq.push(['_trackPageview...
Rails comes with a Rake task notes that shows code comments that start with "TODO", "FIXME", or "OPTIMIZE". While it's generally not good practice to leave them in your...
app/helpers/frontend/slider_helper.rb: * [48] [TODO] this is only temporary till frontend is done However, with Rails' default configuration this task will only look through default file extensions, like .rb, .erb, .css...
...our older projects, we use the mysql2 gem. Unfortunately, versions 0.2.x (required for Rails 2.3) and versions 0.3.x (required for Rails 3.2) can no longer be installed on...
...to errors when compiling the native extension, or a segfaults when using it. For Rails 4.2, mysql2 version 0.4.10 seems to work okay. If you still have issues, upgrade to...
January has been a very bad month for Ruby on Rails developers, with two high-severity security bugs permitting remote code execution found in the framework and a separate-but...
...related compromise on rubygems.org, a community resource which virtually all Ruby on Rails developers sit downstream of. Many startups use Ruby on Rails. Other startups don’t but, like the...
The colors in Rails log files are helpful when watching them but, since they are ANSI color codes like ^[[4;36;1m, can be annoying when you are reading the...
When you require the Ruby debugger to be available from your Rails console (e.g. you want to inspect a method's magic), you need to enable it explicitly: script/console --debugger
...is to "vendor" the gem by copying it into the vendor/gems directory of your Rails project. You can then make any changes you require and Rails will use the vendored...
...after a server restart. Unfortunately you need to perform some additional steps to marry Rails and the copied gem. This notes describes what to do. With Bundler
...Using unguessable URLs. This is fast (because Apache can deliver assets without going through Rails), but less secure. When going with the "unguessable URL" approach, it is possible to somewhat...
...with SecureRandom.hex(32), and also put it as url_signature_secret into your secrets.yml. Rails helper To generate an expiring URL, use the following helper: def sign_public_path(path...
view_context.helper_method('args') Rails 2 ApplicationController.helpers.helper_method('args') Also see How to use helper methods inside a model...
...cover in detail how to utilize both views and materialized views within Ruby on Rails, and we can even take a look at creating and modifying them with database migrations...