Using beginning_of_day or end_of_day on Date or DateTime objects in Rails 2.x applications will never respect time zones, which is horrible.\ This is fixed in...
...Rails 3, though. Even when using Date.current or DateTime.current you will get regular Time or DateTime objects: >> Date.current.beginning_of_day.class => Time # not a ActiveSupport::TimeWithZone as expected >> DateTime.current.beginning_of_day.class => DateTime # not a ActiveSupport...
...tidy, we recently started to namespace controllers. With the :controller option you can tell Rails which controller to use for a path or resource. For nested resources, Rails will determine...
...following code in routes.rb … resources :users do resource :profile, controller: 'users/profiles' #[1] end … makes Rails expect the following directory structure: app/ controllers/ users/ profiles_controller.rb users_controller.rb ... views/ users/ profiles/ show.html.haml index.html.haml...
If you need to enable NewRelic monitoring on certain machines within the same Rails environment, a simple solution is to utilize the respective hostnames of you machines. For example, if...
...CustomNewRelicConfiguration.enable_on_current_host? %> FYI: The newrelic.yml config file is ERB parsed when the Rails environment is booted, CustomNewRelicConfiguration.enable_on_current_host? gets evaluated and NewRelic is enabled on the...
When CoffeeScript was added to Rails 3.1 they forgot one very important part, the ability to use it when responding to JavaScript (JS) requests! In Rails 3.1 it’s incredibly...
I have been playing around with RESTful Rails recently. Below is my collection or Rails REST howtos, tutorials and other resources I have found so far...
ObjectiveResource is an Objective-C port of Ruby on Rails' ActiveResource. It provides a way to serialize objects to and from Rails' standard RESTful web-services (via XML or JSON...
There are many wonderful things about Rails and the Rails ecosystem. A clean, well-lighted path for keeping all your extensions up to date is not one of them...
This is a visualization of the files that will be generated by some useful rails generators. Invoke a generator from command line via rails generate GENERATOR [args] [options]. List all...
...generators (including rails generators) with rails g -h. generator model migration controller entry in routes.rb views tests scaffold ✔ ✔ ✔ ✔ ✔ ✔ resource ✔ ✔ ✔ ✔ ✔ model ✔ ✔ ✔ controller ✔ ✔ ✔ migration ✔ Also see this blog post...
...maybe the rubygems-bundler that RVM supplies by default) no longer working on old Rails versions (it seems to work on applications running on Rails 3.2 + Ruby 1.8.7).
...sitemap.xml' => 'feeds#sitemap', :constraints => { :format => 'xml' }, :as => 'sitemap' The mistake is to match sitemap.xml. Rails will by default strip any dot-anything, remember it as desired format and forward the...
...making .xml part of the match, it is not available for format determination and Rails will set the format to html. Unfortunately, the constraint won't complain in this case...
...but install the version from the webpage instead. Get Bundler: sudo gem install bundler Rails and other gems for a project should now be installed via bundle install from the...
...project directory. If you need Rails and don't have a Gemfile you can do it old-school: sudo gem install rails -v=2.3.12. You will also need Ubuntu development...
The most obvious way to use spring is to call it explicitly: spring rails console spring rake db:migrate Binstubs Binstubs are wrapper scripts around executables. In Rails they...
...all, your binstubs will be using Spring. bin/rails console bin/rake db:migrate bundle exec rails ... Bundle exec is inconsistent when it comes to spring. Some commands will use it, some...
There are a few ways to access view helpers from the Rails console. The easiest way is the helper shortcut: helper.translate 'i18n.string' helper.your_helper_method If the desired helper renders...
...a view template, you need this setup: view_paths = Rails::Application::Configuration.new(Rails.root).paths["app/views"] av_helper = ActionView::Base.new(view_paths).extend YourHelperModule av_helper.your_helper_method
Starting with Rails 4.0, when you get an exception reported via the ExceptionNotification gem, you will only see a very short backtrace with all backtrace lines from gems or ruby...
...libraries missing. This happens, because the ExceptionNotification gem uses Rails' default backtrace cleaner. To get a full backtrace in exception emails, you can remove the comment from this line in...
In Rails 3.1+, instead of defining a separate up and down method you can define a single method change: class AddComparisonFieldsToReport < ActiveRecord::Migration def change add_column :reports, :compare, :boolean...
...additional step to keep your cookies valid. Issue Sidekiq::Web is mounted into your Rails application and will use the Rails session cookie for protection from CSRF attacs. While it...
...Sidekiq::Web like this: # config/initializers/sidekiq.rb require 'sidekiq/web' Sidekiq::Web.set :sessions, domain: <domain here, e.g. Rails.configuration.x.cookie_domain...
...list like this: ----- Passenger processes ----- PID VMSize Private Name ------------------------------- 671 112.9 MB 95.5 MB Rails: /opt/www/project1/current 707 79.4 MB 60.5 MB Rails: /opt/www/project2/current 1094 88.1 MB 69.3 MB Rails: /opt/www/project3/current...
...MB 62.6 MB Rails: /opt/www/project4/current 1269 72.9 MB 55.6 MB Rails: /opt/www/project5/current
...go, all you need to do is prefix every command with zeus. That means rails server becomes zeus server, rails console becomes zeus console, and so on. From the Github...
Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second. Requirements: OS X 10.7+ or Linux...
...it will look like this: >> Socket.gethostname => "happycat" That should work right away for your Rails application. For plain Ruby, you first need to do: require 'socket'
...often is) different from the host that a user is requesting in their current Rails session (request.host). Also keep in mind that hostname might give you the FQDN depending on...
Add deprecation warnings and their solution or link to available solutions. Global access to Rake DSL methods is deprecated. Please...
...require to require_relative where I loaded RSpec factories in Cucumber's env.rb (the Rails application root is no longer in the load path by default) replacing the old debugger...
...to your Gemfile. iconv is a part of Ruby that was removed in 2.0. Rails 3 seems to depend on it. All the pain with magic # encoding: utf-8 comments...
You don't need a Rails application to use Sass. Even when you're working on a static site you can generate your CSS through Sass. Install Sass with sudo...
...gitignore to not exclude public/stylesheets/*.css, since stylesheets aren't being generated automatically without Rails (this would bite you after a deploy). Instead exclude .sass-cache, which will be created...
Run bundle update cucumber capybara cucumber-rails to update to the newest versions. Backup your features/support/path.rb to be able to add your own paths again after the cucumber installation script...
...your features/support/env.rb file to be able to reintegrate parts like your blueprints setup: ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'spec/support/blueprints' Run $ rails generate cucumber:install...
...images, this slows down development response times. You can fix that by defining a Rails route like this: if Rails.env.development? scope format: true, constraints: { format: /jpg|png|gif/ } do