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

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

Any 404 error that is caused by something not found in your Rails app will render a nice message using your default layout. Similarly, you may catch and...

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

If you need to log to a file you can use Ruby's Logger class: require 'logger'

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

medium.com

Root Insurance runs their application as a monolithic Rails application – but they've modularized it inside its repository. Here is their approach in summary: Strategy Keep all code in a...

...merges and deploys across N repos. Other resources https://www.airpair.com/ruby-on-rails/posts/ruby-on-rails-the-modular-way https://engineering.gusto.com/building-toward-a-modular-monolith https://railsconf.com/2020/video/vladimir-dementyev-between-monoliths-and-microservices

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',

api.rubyonrails.org

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

...you need to, probably your whole application should be split up. Split it anyway Rails::Engine looks at config.paths['config/routes.rb'] and registers its value with app.routes_reloader. This means you...

...then require them. However, I recommend to put any routing files into config/routes/: # config/routes/example.rb Rails.application.routes.draw do resources :example end After creating your routing files, tell Rails how to find them...

weblog.rubyonrails.org

Rails 3.0 has been underway for a good two years, so it’s with immense pleasure that we can declare it’s finally here. We’ve brought the work of...

railslab.newrelic.com

Learn everything you need to know about Scaling your Rails app through 13 informative Screencasts produced by Gregg Pollack with the support of New Relic...

axonflux.com

There are a bunch of basic functional elements to building out a popular Rails app that I've never really seen explained in one place, but we had to learn...

railstutorial.org

A thorough introduction to web development with Ruby on Rails

github.com

bower-rails is a great solution for managing vendored assets in your Rails app. It feels especially much more convenient and easier to update assets when going this way.

...rails generates a Bowerfile that works much like the Gemfile you're used to. Just specify your dependencies and run rake bower:install. You can find available packages here.

stackoverflow.com

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