See our new comprehensive guide to upgrading every Rails 2 version ever...

...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...

If you get an error like this ... can’t find executable rails for rails-3.2.3 (Gem::Exception) ... one of several things might be wrong. You're using RVM

...possible that you have a system-wide gem executable (like rails) that requires a gem that is not available in the current RVM Ruby or gemset. Check what Ruby you...

Yesterday, Rails fixed a security issue (CVE-2014-3514) in Rails 4+. It was possible to use .where or .create_with to bypass Rails' Strong Parameters: user.blog_posts.create_with...

...know .create_with existed, have a look at the API. How this applies to Rails 3 In Rails 3, Strong Parameters did not exist, yet. Instead, you used mass assignment...

Note that this seems to affect only recent Rails 2 versions. You will not encounter this until you are writing to the cookie more than once, but when doing so...

Solution This seems to be a bug in Rails, the CookieStore (for sessions) or Rack::Utils.set_cookie_header -- I did not bother looking closer. My problems went away...

Rails flashes (FlashHash) track a list of used keys, which is not respected when comparing flash hashes. This does not concern you under most circumstances. Basics When ActionController picks up...

...method which checks for that: ActionController::Flash::FlashHash.class_eval do # This is from a Rails 2 project. For Rails 3, say: # ActionDispatch::Flash::FlashHash.class_eval do def same?(other_flash...

You may encounter problems with passenger starting an application with an updated rails. If you find an error like this in the apache error log...

...17680/7f4907ae7700 agents/HelperAgent/RequestHandler.h:2210 ]: [Client 19] Cannot checkout session. Error page: This application is a Rails 3 application, but it was wrongly detected as a Rails 1 or Rails 2 application...

...an API which you could maybe use! You can connect to the GitLab internal Rails with executing gitlab-rails console. It might be slow at times, especially if you use...

The following code listings are expected to be entered inside the gitlab-rails console. Remove GitLab Labels from already closed Issues p = Project.find_by_id(1)

github.com

...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...

...token authenticity" even if csrf token is present? As :domain => :all is set in Rails 3, local session cookies seem not to be set unless you specify a top-level...

Solutions Use a dns wildcard service like lvh.me and set :domain => 'lvh.me' if Rails.env.development? Then you can access your local server with lvh.me:3000 or anysubdomain.lvh.me:3000. Another way is, to...

...setting the :x_sendfile option to true. This option is activated by default for Rails 3, so you need to understand this. What this option does is not to send...

...as a new response header: X-Sendfile: /opt/www/awesome-project/shared/downloads/image.png When the response comes back from Rails to Apache for delivery, Apache will detect that header and replace the empty response body...

Plugins (and gems) are typically tested using a complete sample rails application that lives in the spec folder of the plugin. If your gem is supposed to work with multiple...

...versions of Rails, you might want to use to separate apps - one for each rails version. For best practice examples that give you full coverage with minimal repitition of code...

...exceptions, maybe some bot visits your site requesting silly formats like: http://www.rails-app.com/makandra.html-username-2000 # => Rails tries to retrieve 'makandra' with format 'html-username-2000' Just restrict accepted format parameters for...

...not_acceptable) end end end end Note: request.format more reliably tells the format, but includes Rails-required formats such as application/x-www-form-urlencoded (which we must not refuse). For our purposes, getting...

...not work with complex sorting constraints and may even silently create malformed SQL for rails < 5. Take a look at this query which orders by the maximum of two columns...

...SELECT "pages".* FROM "pages" ORDER BY GREATEST(pages.published_from_de, pages.published_from_en) DESC Rails 4 Rails 4 will not immediately raise but creates malformed SQL when trying to use...

You want Spring for super-fast binstubs like bin/rails or bin/rspec which avoid Rails boot time. You want parallel_tests to speed up full test runs of large test suites...

...not an issue for full test runs that take several minutes, we can accept Rails booting a few seconds. In your binstubs, there should be something like this: begin

...possible to access Rails config (for example secrets) from within your webpack bundles, thanks to rails-erb-loader. When using webpacker, the setup is like this: Install rails-erb-loader...

...yarn add rails-erb-loader Add this to your config/webpacker/environment.js: environment.loaders.prepend('erb', { test: /\.erb$/, enforce: 'pre', use: [{ loader: 'rails-erb-loader', }] }) Start using erb. For example, in a file api_config.js.erb...

makandra dev

...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...

...locale/de/app.po for every locale you want to use use method "_" like _('text') in your rails code run rake gettext:find to let GetText find all translations used translate messages in...

...locales = [ 'en', 'de' ] FastGettext.add_text_domain('app', :path=>'locale', :type=>:po) FastGettext.text_domain = 'app' Rails::Initializer.run do |config| # Versionsnummern selber rausfinden: config.gem 'spreadsheet', :version => '=0.6.4.1' config.gem "fast_gettext", :version...

rails-assets.org

...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...

In Rails 2, you could use link_to_remote...

...:update => 'id' to...

...automatically replace the content of $('#id'). To do the same in Rails 3, include usual rails-ujs JavaScript, and put this into your application.js: $(function() { $('[data-remote][data-replace]')

Watch out when saying something like 1.year in Rails. The result is not a Fixnum and can cause unexpected errors when the receiving end expects a Fixnum. While anything from...

...seconds to months are Fixnums, a year is a Float in Rails -- when called on a Fixnum itself: >> 10.seconds.class => Fixnum >> 2.minutes.class => Fixnum >> 24.hours.class => Fixnum >> 28.days.class => Fixnum >> 9.months.class => Fixnum >> 1.year.class

ariejan.net

Rails understands a :limit options when you create columns in a migration. Its meaning depends on the column type, and sometimes the supplied value. The documentation states that :limit sets...

In Rails 5 you can say: ApplicationController.render( :template => 'users/index', :layout => 'my_layout', :assigns => { users: @users } ) If a Request Environment is needed you can set attributes default attributes or initialize a...

...host: 'example.org', https: false ) renderer.render( :template => 'users/index', :layout => 'my_layout', :assigns => { users: @users } ) In Rails 3 and 4 you can say: ApplicationController.new.render_to_string( :template => 'users/index', :layout => 'my_layout',