Karl Bryan Paragua kbparagua

View belongs_to.rb
1 2 3 4 5 6 7 8 9 10
class Item < ActiveRecord::Base
attr_accessible :container, :container_id, :value
belongs_to :container
accepts_nested_attributes_for :container
end
 
 
class Container < ActiveRecord::Base
end
View foo.js
1 2 3 4 5 6 7 8 9
function Foo(){
this.z = 400;
this.x(function(){ return this.z; });
}
 
Foo.prototype.x = function(y){ this.a = y(); };
 
var b = new Foo();
alert(b.a);
View frontendDevlopmentBookmarks.md
View checlist.md

Security is Hard

Massive Assignment

  • watch for ActiveRecord Relation, like has_many, has_many :through
  • watch for user_roles, `group_users
  • UPDATE action

Admin

View test.js
1 2 3 4 5 6 7 8 9 10
// controller file
(function(){
var self = Paloma.Callbacks.Controller = {};
before('new', 'edit').perform(function(params){
// Do something here
}).given('condition');
 
after_all().perform('method name').given(function(){ return false; });
View slug.rb
1 2 3 4 5 6 7 8 9 10
# Trade-offs
# - fast category manipulation. can change parents without the need to update all sub category slugs
# - slow reading. finding category by slug will fetch all parent category
 
 
class Store < ActiveRecord::Base
 
def category_by_slug slug
slug = slug.split '/'
name = slug.pop
View 0_using_delagate.rb
1 2 3 4 5 6 7 8 9 10
# used MANY times all over the application
@post.user_is_banned?
 
 
class User < ActiveRecord::Base
has_many :posts
 
def is_banned?
self.banned == 1
end
View _form.haml
1 2 3 4 5 6 7 8 9 10
-# options = [["Human-1", "Romeo"], ["Human-2", "Juliet"], ["Animal-1", "Blackie"]]
-options = (Human.all + Animal.all).map { |friend| [friend.formatted_type_and_id, friend.name] }
=form_for @human do |f|
Name:
=f.text_field :name
Friend:
=f.select :formatted_friend, options
View Human.rb
1 2 3 4 5 6 7 8 9 10
class Human < ActiveRecord::Base
attr_accessible :name, :formatted_friend
belongs_to :friend, :polymorphic => true
has_many :friends, :as => :friend
 
validates_presence_of :name, :friend
def formatted_friend= type_and_id
if type_and_id.present?
View Human.rb
1 2 3 4 5 6 7 8 9 10
class Human < ActiveRecord::Base
attr_accessible :name, :formatted_friend
attr_accessor :formatted_friend
 
belongs_to :friend, :polymorphic => true
has_many :friends, :as => :friend
 
validates_presence_of :name, :friend
before_validation :set_friend
Something went wrong with that request. Please try again.