🐻 🐨
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
# Instead of this | |
after_create :advance_plan | |
def advance_plan | |
plan.advance if plan | |
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
# Show a user-friendly version of our identifier | |
Status: <%= current_user.status.humanize %> | |
# Now we need to customize some of them, use I18n | |
Status: <%= t current_user.status, default: current_user.status.humanize %> | |
# But that's polluting our I18n namespace | |
Status: <%= t :"user.status.#{ current_user.status }", default: current_user.status.humanize %> | |
# Ok, this is getting out of hand, lets refactor this to the model |
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 ApplicationDecorator < Draper::Base | |
# See +ApplicationDecorator.humanize+ | |
def humanize(attribute, key = model.send(attribute), default = key.to_s.humanize) | |
self.class.humanize attribute, key, default | |
end | |
# By default, humanize the attributes listed. | |
# | |
# Contrived Example: |
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 ApplicationHelper | |
def current_user | |
super.decorator | |
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
class Asset < AR | |
end | |
class Alert < AR | |
belongs_to :asset | |
has_many :logs | |
accepts_nested_attributes_for :logs | |
end | |
class Log < AR |
Put the ruby file in .git/hooks/post-commit
Create a deploy script as .deploy_*
Example:
# File: .deploy_production
scp -R html example.com:public_html
Then use "deploy *
" in your commit message.
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
def page_title() | |
object_name = controller_name.singularize | |
if controller.instance_variables.include?(('@' + object_name).to_sym) | |
locals = { | |
object_name.to_sym => controller.instance_variable_get('@' + object_name).to_s | |
} | |
else | |
locals = {} | |
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 DataMapper | |
# DataMapper::Sweeper provides an observer to model changes that have access | |
# to the controller invoking the changes. | |
# | |
# The api for DataMapper::Sweeper is similar to DataMapper::Observer, but | |
# there is one important difference: in DataMapper::Observer .before and | |
# .after blocks are evaluated in the context of the resource instance. | |
# However, DataMapper::Sweeper .before and .after blocks are evaluated in the | |
# context of an instance of your Sweeper class, and missing methods are |
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
# Some values, they are themselves | |
true # => true | |
false # => false | |
"value" # => "value" | |
0 # => 0 | |
nil # => nil | |