Skip to content

Instantly share code, notes, and snippets.

class AddFlagToSomeModels < ActiveRecord::Migration
def self.up
add_column :some_models, :flag, :boolean, :default => true, :null => false
SomeModel.first.update_attribute(:flag, false)
end
def self.down
remove_column :some_models, :active
end
#routes.rb
resources :users
#spec.rb
before do
@user = User.new(:name => "fakename")
@user.save
end
u = User.create!(:name => "user1", :adderss => "address1", :current_job => "job1")
u.address = "address2"
u.current_job = "job2"
u.current_job_changed? # => true
u.address_changed? # => true
u.changed? # => true
u.changed # => ['address', 'current_job']
#Gemfile
gem 'trackit'
class User < ActiveRecord::Base
attr_accessible :name
has_many :accounts
end
class Account < ActiveRecord::Base
attr_accessible :kind, :user_id
belongs_to :user
end
has_many :accounts do
def <<(account)
account.kind = "UserAccount"
proxy_association.owner.accounts += [account]
end
end
has_many :accounts do
def recent
where('accounts.created_at > ?', 5.days.ago)
end
end
module AccountOfUser
def <<(account)
account.kind = "UserAccount"
proxy_association.owner.accounts += [account]
end
end
class User < ActiveRecord::Base
attr_accessible :name
has_many :accounts, :extend => AccountOfUser
this.model.save()
.always(function() {
// Do Something here
});
window.FormView = Backbone.View.extend({
events: { "tap #submit_form_button" : "submitForm" },
.
.
.
submitForm: function(){
var form = $("#my_form");
form.validate({
rules:{...},
messages:{...},