When a config.cache_classes setting is true in production mode and false in development mode.app boots, the ActiveRecord classes reflect on the database to determine which attributes and associations to add to the models. The
During development, we can write and run a migration and see the change take effect without restarting the web server but in production we need to restart the server for the ActiveRecord classes to learn about the new information from the database. …
This means that your ActiveRecord instances take priority - so pane methods don't overwrite your own code. It also allows for method_missing metaprogramming in your models (and ActiveRecord itself) - but otherwise, you can get access to the useful metadata Sphinx can provide, without monkeypatching objects on the fly.
If you're writing your own panes, the only requirement is that the initializer must accept three arguments: the search context, the underlying search result object, …
It sounds great in theory, but it's harder in practice.
It's good to be aware of such hidden functionalities. At some point, they can become explicit features, with their own tests, so that it's never broken.
If you know more such features, share them in the comments.
In the previous post, I highlighted the typical , that I encountered during my research on better ways of working on Rails apps. The bugs were often security-related: bugs
The main common point of the bugs is the ActiveRecord overdose.
ActiveRecord overdose is a surprisingly popular pattern that includes:
putting everything into the model class
fear of adding new non-AR classes
over-relying on convention over configuration When you look at a typical Rails model, …
…of heart . Some parts of the Rails framework are very ambitious engineering — take ActiveRecord, for example. As is true with most software projects, even the people who wrote it the first time don't fully understand what it is doing. You get to start working on rebuilding their undocumented organic knowledge now, and doing security patches later. You might think that you have a helpful ally in the test suite but it is not actually deterministic, because many of the tests rely on …
and so on. StateTransition is an STI subclass of ActiveRecord::Base.
Inside each ‘concrete' transition subclass, AR validations determine whether the transition can be created, given current system state. Callbacks make changes to other models that result from the transitions, as well as trigger other effects like emails.
This shifts emphasis from the models to the transitions themselves. Model classes don't get cluttered with logic related to multiple transitions - that …
Searchlight - Searching gem that minimizes magic. Comes with ActiveRecord integration module.
Open Source Report Card - a user's activity for interesting patterns.
Fargo - outliner that stores its files in your .
…collection of dependencies. We have one for Sinatra, one for Resque and one for ActiveRecord outside of Rails. The exact versions are specified by an Envfile: suite_condition("Sinatra not compatible with 1.8.6") do RUBY_VERSION != '1.8.6' end
gemfile <<-RB gem 'sinatra', '1.3.3' gem 'rack-test', :require => 'rack/test' RB
gemfile <<-RB gem 'sinatra', '1.2.8' gem 'rack-test', …
Interactive mruby - irb running in your browser.
Rails 4.0: - The official announcement. 1 released!
Starter App - Using ruby 2, 4, , , and Bootstrap.
Callback logging - Some diagnostic code I whipped up yesterday to add ActiveRecord callbacks to the development log.
activerecord-callback_notification - This one didn't do quite what I want, but I borrowed some of its code to start from.
…follow SOLID principles without radically decoupling your app from Rails and especially ActiveRecord. Instead, you let AR objects do what they're good at: representing data. You push behavior, as much as possible, out into objects. What you should end up with is a handful of models that encapsulate the tables in your database and a bunch of classes that encapsulate the logic and behavior of your application; whether these classes live in app/models or somewhere else is a matter of personal …