Skip to content

Instantly share code, notes, and snippets.

@myowin76
myowin76 / emberInstallEmberData
Created July 23, 2013 13:19
ember install ember-data
git clone --depth 1 git://github.com/emberjs/data
cd data
bundle
bundle exec rake dist
copy dist/ember-data-min.js file to your project
@myowin76
myowin76 / emberEachLoop.js
Created July 23, 2013 11:19
ember each loop
{{#each person in list}}
<li>{{person.name}}</li>
{{else}}
There are none.
{{/each}}
{{#each person in list}}
{{#with person}}
<li>{{name}}</li>
{{/with}}
@myowin76
myowin76 / emberNavList.js
Created July 23, 2013 09:16
ember navigation list
<script type="text/x-handlebars" data-template-name="application">
<nav>
<ul>
<li>{{#linkTo "index"}}Home{{/linkTo}}</li>
<li>{{#linkTo "about"}}About{{/linkTo}}
<ul>
<li>{{#linkTo "about.team"}}Team{{/linkTo}}</li>
</ul>
</li>
<li>{{#linkTo "contact"}}Contact{{/linkTo}}</li>
@myowin76
myowin76 / rails3CreateGem.rb
Created July 22, 2013 16:01
rails3 create your own ruby gem
_
@myowin76
myowin76 / rails3ListTables.rb
Created July 22, 2013 15:56
rails3 list the active record tables
// controller
@tables = ActiveRecord::Base.connection.tables.sort
@myowin76
myowin76 / rails3PrawnPDF.rb
Created July 22, 2013 12:58
rails3 prawn generate pdf
gem 'prawn'
// Recipie Model
def shopping_list_pdf
shopping_list = ingredients.map do |ingredient|
[ingredient.name, ingredient.quantity]
end
pdf = Prawn::Document.new
pdf.table([[ "Item", "Quantity" ], *shopping_list]) do |t|
@myowin76
myowin76 / rails2CopyRecordAndCreate.rb
Created July 19, 2013 15:55
rails3 copy the record and create new
// album.rb Model
class Album < ActiveRecord::Base
def copy
self.class.new.tap do |new_album|
attributes.each do |key, value|
new_album.send("#{key}=", value) unless key == "id"
end
new_album.save
end
end
@myowin76
myowin76 / rails3AjaxToggleAttributes.rb
Created July 19, 2013 11:29
rails3 ajax toggle attributes
// Structure
rails g scaffold Article name:string approved:boolean
// routes
resources :articles do
get 'toggle_approve', :on => :member
end
// Article Helper
def approve_link_text(approvable)
@myowin76
myowin76 / rails3CustomValidation.rb
Created July 19, 2013 11:21
rails3 custom validation
validates_format_of :ssn, :with => /^[\d]{3}-[\d]{2}-[\d]{4}$/, :message => "must be of format ###-##-####" ==================================================== // lib/custom_validations.rb module CustomValidations def validates_ssn(*attr_names) attr_names.each do |attr_name| validates_format_of attr_name, :with => /^[\d]{3}-[\d]{2}-[\d]{4}$/, :message => "must be of format ###-##-####" end end end ActiveRecord::Base.extend(CustomValidations) // config/environment.rb require 'custom_validations' // model/student.rb class Student < ActiveRecord::Base validates_presence_of :name validates_ssn :ssn end
@myowin76
myowin76 / jqueryDatepicker
Created July 17, 2013 10:15
jQuery Datepicker
$('#search_fromDate').datepicker(
{
dateFormat: 'dd/mm/yy',
onClose: function( selectedDate ){
$( "#search_toDate" ).datepicker( "option", "minDate", selectedDate );
$('#search_fromDate').blur(); //or .focusout();
}
}
);