Rails 5 (don't know about the others) comes with an initializer wrap_parameters.rb. Here you can tell rails to wrap parameters send to your controllers for specific formats into a...
...used to when you are dealing with form payloads. This is especially handy because Rails puts some stuff in the params which does not really belong there IMHO. For instance...
...in development. This is usually useful, but when you run into issues with the Rails autoloader, you should take a look at what it's doing. For me this was...
...of auto-loading classes inside a thread which caused the application to stop responding. Rails 4.x ActiveSupport::Dependencies includes logging support. It is easy to use: ActiveSupport::Dependencies.logger = Rails.logger...
...writing a piece of reusable code, you sometimes need to have separate code for Rails 2 and Rails 3. You can distinguish between Rails versions like this: if Rails.version...
...mind the quotes # Rails 2 code goes here else # Rails 3+ code goes here
...Rubygems) it will provide the Jasmine library to your asset pipeline. When you then install rails-assets-jasmine-fixture through Rails Assets you will get another (possibly conflicting) copy of...
...Jasmine installed through Rails Assets. This is because rails-assets-jasmine-fixture depends on rails-assets-jasmine and does not realize that the Jasmine dependency was already satisfied through jasmine...
You will need to upgrade to RSpec >= 2 and rspec-rails >= 2 for Rails 3. Here are some hints to get started: In RSpec 2 the executable is rspec, not...
RSpec and rspec-rails have been completely refactored internally. All RSpec classes have been renamed from Spec::Something to RSpec::Something. This also means that every require 'spec/something' must...
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).
If a model inherits from others or uses many concerns / traits, it might be hard to see in the code...
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...
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...
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...
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...