This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #routes.rb | |
| resources :users | |
| #spec.rb | |
| before do | |
| @user = User.new(:name => "fakename") | |
| @user.save | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Gemfile | |
| gem 'trackit' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| attr_accessible :name | |
| has_many :accounts | |
| end | |
| class Account < ActiveRecord::Base | |
| attr_accessible :kind, :user_id | |
| belongs_to :user | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| has_many :accounts do | |
| def <<(account) | |
| account.kind = "UserAccount" | |
| proxy_association.owner.accounts += [account] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| has_many :accounts do | |
| def recent | |
| where('accounts.created_at > ?', 5.days.ago) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| this.model.save() | |
| .always(function() { | |
| // Do Something here | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.FormView = Backbone.View.extend({ | |
| events: { "tap #submit_form_button" : "submitForm" }, | |
| . | |
| . | |
| . | |
| submitForm: function(){ | |
| var form = $("#my_form"); | |
| form.validate({ | |
| rules:{...}, | |
| messages:{...}, |
OlderNewer