ruby-debug with Ruby 1.9.3?

Update (April 28, 2012) Try the new debugger gem as a replacement for ruby-debug. (credit to @ryanb) Update (March 2, 2012) Installation of linecache19 and ruby-debug-base19 can be easily done with: bash < <(curl -L https://raw.github.com/gist/1333785) (credit to @fredostarr) Original answer Have you looked at ruby-debug19 on ruby-1.9.3-preview1? Here’s a temporary solution: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug Excerpt from … Read more

Run rake task in controller

I agree with ddfreynee, but in case you know what you need code can look like: require ‘rake’ Rake::Task.clear # necessary to avoid tasks being loaded several times in dev mode Sample::Application.load_tasks # providing your application name is ‘sample’ class RakeController < ApplicationController def run Rake::Task[params[:task]].reenable # in case you’re going to invoke the same … Read more

Ruby: SQLite3::BusyException: database is locked:

For anyone else encountering this issue with SQLite locking in development when a Rails console is open, try this: Just run the following: ActiveRecord::Base.connection.execute(“BEGIN TRANSACTION; END;”) For me anyway, it appears to clear any transaction that the console was holding onto and frees up the database. This is especially a problem for me when running … Read more

Storing arrays in database : JSON vs. serialized array

You can store Arrays and Hashes using ActiveRecord’s serialize declaration: class Comment < ActiveRecord::Base serialize :stuff end comment = Comment.new # stuff: nil comment.stuff = [‘some’, ‘stuff’, ‘as array’] comment.save comment.stuff # => [‘some’, ‘stuff’, ‘as array’] You can specify the class name that the object type should equal to (in this case Array). This … Read more

has_and_belongs_to_many vs has_many through

As far as I can remember, has_and_belongs_to_many gives you a simple lookup table which references your two models. For example, Stories can belong to many categories. Categories can have many stories. Categories_Stories Table story_id | category_id has_many :through gives you a third model which can be used to store various other pieces of information which … Read more

Rails Polymorphic Association with multiple associations on the same model

I have done that in my project. The trick is that photos need a column that will be used in has_one condition to distinguish between primary and secondary photos. Pay attention to what happens in :conditions here. has_one :photo, :as => ‘attachable’, :conditions => {:photo_type => ‘primary_photo’}, :dependent => :destroy has_one :secondary_photo, :class_name => ‘Photo’, … Read more