This file contains 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
alias :save :user_confirm | |
alias :delete :user_confirm | |
def user_confirm(current_user) | |
unless self.user == current_user | |
errors.add(:user, 'Must be you') | |
else | |
super | |
end | |
end |
This file contains 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
<% widget_coffee :my_widget do %> | |
... some coffeescript excluding closure wrapping | |
... this content gets compiled into application.js once. | |
<% end %> | |
<% widget_sass :my_widget do %> | |
... namespaced styling for my_widget | |
... this gets compiled into application.css once. | |
<% end %> |
This file contains 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 AddCategories < ActiveRecord::Migration | |
# def up | |
# create_table :categories do |t| | |
# t.string :name | |
# t.integer :score | |
# ... # other examples | |
# end | |
# end | |
# def down |
This file contains 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 MyClass | |
def initialiser | |
defn /do_([a-z]*)_to_([a-z]*)/, :do_x_to_y | |
end | |
def defn(regex, &proc) | |
@@missing_things = [] if @@missing_things.nil? | |
@@missing_things << [ regex, proc ] | |
end | |
This file contains 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
ship = bodies[1] | |
shipVec = vector(ship:getX(),ship:getY()) | |
planet = bodies[2] | |
planetVec = vector(planet:getX(),planet:getY()) | |
distance = planetVec – shipVec | |
force = 250 / distance:len2() | |
normforce = force*distance | |
bodies[1]:applyImpulse(normforce.x, normforce.y,ship:getX(),ship:getY()) |
This file contains 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
<select | |
ng-model="selected.service_plan" | |
ng-options="item.id as ('£' + item.label) for item in billing_info.service_plans"> | |
</select> | |
what's wrong with looping through stuff rather than come up with some expression language? speed? |
This file contains 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
Say we had the following structure | |
App | |
-> Views | |
-> ABC | |
abc.erb | |
-> partials | |
_a.erb | |
_b.erb | |
_c.erb |
This file contains 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
t=Ticket.arel_table # the arel table to extract subqueries from | |
if params[:title].length > 0 then | |
sqla = t[:title].matches("%#{params[:title]}%") | |
else | |
sqla = nil | |
end | |
if params[:from].length > 0 then | |
sqlb = t[:from].matches("%#{params[:from]}%") |
This file contains 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
tags=Tag.arel_table | |
@tags = Tag.where(tags[:label].matches("%#{params[:term]}%")) |