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...
Rails’ reputation as a relatively secure Web framework is well deserved. Out-of-the-box, there is protection against many common attacks: cross site scripting (XSS), cross site request forgery...
...the default behavior could be more secure. This post explores potential security issues in Rails 3 that are fixed in Rails 4, as well as some that are still risky...
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...
...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...
Spring is a Rails application preloader. When debugging e.g. the rails gem, you'll be wondering why your raise, puts or debugger debugging statements have no effect. That's because...
...you can only write environment variables that subprocesses will see. For tests with a Rails application (i.e., that call rails or rake or other binstubbed commands), this method may help...
...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).
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...
encoding: utf8 username: root password: secret Note if you're on an old Rails version If you're using a Rails version less than 3.1 (e.g. 2.3.x...
...Newer versions no longer include the ActiveRecord adapter (which is part of ActiveRecord since Rails .1). So your Gemfile should say:
...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...
...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...
...presenter may keep them from reinventing the app logics-wheel, but feels like reinventing the Rails-wheel. (Arne) Bad: Duplicate Validations are bound to be problematic. This could have been...
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...
In Ruby on Rails, all the routes of a given application can be found within the config/routes.rb file. You add more and more routes in this file as your project...
...important to find a way to order and maintain your routes. See: Clean your Rails routes: grouping Sometimes the routes.rb grows very fast and each line adds more confusion to...
This will show you how to create a RSS feed that the Feed Validator considers valid. Note that RSS is...
...reason), you can open doc/dependency_decisions.yml and edit the last entry. A word on bower-rails Bower-rails is a Bower wrapper that simplifies Rails integration. Unfortunately, it makes it harder...
...to integrate Bower with LicenseFinder. To get things running, follow these steps: Symlink bower-rails's bower.json to the project root: ln -s vendor/assets/bower.json Create a .bowerrc file at the...
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...
Don't write resources :people, :concerns => :trashable Write resources :people do concerns :trashable end Why Writing a controller...
...port and the username (default root) and password (default msandbox). When working on a Rails project, you need to paste all of that into your config/database.yml. Connecting to a sandbox...
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...
...got this error after upgrading Ruby from 2.4.5 to 2.6.4 when I opened the Rails console - rails server still worked. Running via Spring preloader in process 14679 Loading development environment...
Traceback (most recent call last): .../lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:175:in 'fork': No such file to load -- irb/encoding_aliases.rb (LoadError) .../lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:175:in 'fork': undefined method 'reject!' for nil:NilClass (NoMethodError) .../lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb...
Rails' ActiveSupport::TimeWithZone objects have both a timezone code and offset, e.g. Thu, 28 Mar 2019 16:00:00 CET +01:00. Ruby's stdlib TZInfo also has time zones...
...chances are you'll end up in the wrong time zone. This is why Rails actually uses a long list of time zone names with have names like "London" or...
...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...
If you need to log to a file you can use Ruby's Logger class: require 'logger'
If you are using Angular and want something like Rails' simple_format which HTML-formats a plain-text input into paragraphs and line breaks, this directive is for you.