Pages tagged activerecord:

Ryan's Scraps: What's New in Edge Rails: Nested Object Forms
http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes

We were all teased a few months ago about the possibility of finally solving the nested model/complex forms problem in Rails, but were then cruelly notified that it wasn’t quite ready for prime time. But our day has come – the most requested feature for Rails 2.3, the ability to handle multiple models in a single form, is here.
Scheduled for Rails 2.3
nkallen's cache-money at master — GitHub
http://github.com/nkallen/cache-money/tree/master
Active record memory cache.
A Write-Through Cacheing Library for ActiveRecord
class Message < ActiveRecord::Base
Rails Forms microformat « Trek
http://wonderfullyflawed.com/2009/02/17/rails-forms-microformat/
Trek Rails Forms microformat This article has been updated to reflect the latest patterns in Rails 2.3 edge (based mostly on this commit) If you’ve been relying on Rails form helpers to generate forms, then you may have missed the interesting little microformat used to pass application data to and fro. In case you didn’t know, form data is passed as part of the request body as a set of key/values pairs in plain text (if you’re using get as a method for a form, it’s that url section like this: ?name=widget12&price=22). The name attribute of the form inputs are the keys (here name and price), and the value is whatever the user entered or selected (widget12 and 22). Most languages/frameworks for the web will reconstitute these pairs as objects accessible to the programmer. For example <input name='widget_name' /> is accessed with $_POST["widget_name"] in php, self.request.get("widget_name") on App Engine, and params[:widget_name] in Rails. This format can only pass a single value f
One of the most comprehensive articles on rails forms. Includes the newly added nested attributes stuff.
ActiveRecord Optimization with Scrooge - igvita.com
http://www.igvita.com/2009/02/27/activerecord-optimization-with-scrooge/
Plugin that monitors the fields you're actually using from queries you make and over time dynamically adjusts your queries to retrieve only the fields you need. Apparently includes some magic to go re-query for more fields if you attempt to use one you hadn't loaded in the trimmed query. Amazing-looking stuff, though since we're currently using a DB on the same machine, transferring lots of extra data isn't nearly as expensive.
Dynamic query optimization is a hotbed of research in the database industry. Each and every query you execute goes through a rigorous optimization phase which tries to squeeze every last bit of performance: deciding which indexes to use, the execution order and sort order to minimize the number in-memory tables, etc. However, one thing the database has no access to is the application layer knowledge of which data the user is actually using after it is retrieved. Often times, the query fetches all of the columns when only a few are required, which is exactly the pattern that Lourens Naudé is seeking to optimize with his new plugin: scrooge.
Dynamic Query Optimization
How to Add Simple Permissions into Your Simple App. Also, Thoughtbot Rules! // RailsTips by John Nunemaker
http://railstips.org/2009/4/20/how-to-add-simple-permissions-into-your-simple-app-also-thoughtbot-rules
I didn't realize the automatic boolean attributes part.
how to use mixins in Rails, with loads of useful stuff about testing at the end
Shoulda examples
AirBlog — A Paper Trail For Your Models
http://blog.airbladesoftware.com/2009/6/23/a-paper-trail-for-your-models
PaperTrail lets you track changes to your Rails app’s models’ data. It’s good for auditing or versioning. You can see how a model looked at any stage in its lifecycle and even undelete it after it’s been destroyed.
acts_as_versioned simply_audited
That’s Not a Memory Leak, It’s Bloat | Engine Yard Blog
http://www.engineyard.com/blog/2009/thats-not-a-memory-leak-its-bloat/
ou combined memory
The Rails State Machine « Envy Labs
http://blog.envylabs.com/2009/08/the-rails-state-machine/
include ActiveModel::StateMachine
Ruby on Rails recently added a built-in ActiveModel::StateMachine implementation and even more recently tied it in to ActiveRecord. And, for being a built-in library, it’s pretty damned fully-featured.
NoSQL with MySQL in Ruby - Friendly
http://friendlyorm.com/
James on Software | Introducing Friendly: NoSQL With MySQL in Ruby
http://jamesgolick.com/2009/12/16/introducing-friendly-nosql-with-mysql-in-ruby.html
I've been a big proponent of NoSQL for a while. I have played with just about all of the new generation of data stores. We almost got cassandra running in production once, and we've been running mongodb in production for about six months now. But, here's the thing: as awesome as these new dbs are, they're still young. Our app generates a ton of data and gets pretty serious traffic. So, we started hitting walls quickly. To make a long story short, we decided to fall back to MySQL. It's battle hardened. We know its production characteristics and limitations. Backups are a science. We know we can count on it. But, we have a lot of data, and adding fields and indexes was starting to get painful. Flexible schemas are one of the things that attracted me to NoSQL in the first place. Then, I remembered this article about How FriendFeed uses MySQL to store schema-less data. So, I decided to implement the system they describe in the article. Since we put Friendly in to production, we've seen
Friendly makes MySQL look like a document store. When you save an object, it seralizes all of its attributes to JSON and stores them in a single field. To query your data, Friendly creates and maintains indexes in separate tables. It even has write-through and read-through caching built right in.
Introducing Friendly: NoSQL With MySQL in Ruby Dec 16 2009 I've been a big proponent of NoSQL for a while. I have played with just about all of the new generation of data stores. We almost got cassandra running in production once, and we've been running mongodb in production for about six months now.
has_many :bugs, :through => :rails: Active Record Query Interface 3.0
http://m.onkey.org/2010/1/22/active-record-query-interface
In short, passing options hash containing :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock to any of the ActiveRecord provided class methods, is now deprecated.
Database Versioning
http://adam.blog.heroku.com/past/2009/3/2/database_versioning/
Migrations bother me. On one hand, migrations are the best solution we have for the problem of versioning databases. The scope of that problem includes merging schema changes from different developers, applying schema changes to production data, and creating a DRY representation of the schema. But even though migrations is the best solution we have, it still isn’t a very good one.
Check the brainstorming at the end. I love where he's going. Short version: a schema.yml file identified by its SHA1 hash. Migrations are for translating data between versions. Great comments at the end by the smart people in the community.
On one hand, migrations are the best solution we have for the problem of versioning databases. The scope of that problem includes merging schema changes from different developers, applying schema changes to production data, and creating a DRY representation of the schema.
semantic art - ruby - Using default_scope to recreate acts_as_paranoid in ActiveRecord 2.3
http://blog.semanticart.com/using_default_scope_to_recreate_acts_as_paranoid
def self.find_with_destroyed *args self.with_exclusive_scope { find(*args) } end
Rails 2.3 gives us “default_scope” which was described by Ryan Daigle as allowing you to “specify default ordering, and other scopes, in edge rails directly in your ActiveRecord model.” Ryan’s post gives some good examples of when you might want to use this (specifically on models where you always want them sorted in a specific manner). In the comments of that post, Ryan Bates suggests that this might be useful for “simulating destroying a model (like acts_as_paranoid).” Indeed this is possible and the idea of using scoping to create this is both present in acts_as_paranoid itself and also has been brought up before. In this article I’m going to reinvent the wheel using default_scope to illustrate how powerful default_scope is and how trivial it makes this task. You can keep track of the finished product in my is_paranoid gem.