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 AbstractClass | |
def initialize(attributes) | |
attributes.each do |name, value| | |
unless self.respond_to?("#{name}=") | |
self.class.send(:attr_accessor, name) | |
end | |
self.send("#{name}=", value) | |
end | |
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
plain_text_password_validators = User.validators.select { |v| v.attributes.include?(:plain_text_password) } | |
callback_filters = User._validate_callbacks.select{ |vc| plain_text_password_validators.include?(vc.raw_filter) }.map{ |vc| vc.filter } | |
callback_filters.each do |cf| | |
User.skip_callback(:validate, :before, cf) | |
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
1.9.3p392 :002 > Postcode | |
=> Postcode(id: integer, postcode: string, long: decimal, lat: decimal, address: string, bias: string, data: text, tries: integer, updated_at: datetime, created_at: datetime) | |
1.9.3p392 :003 > |
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
AppUser.authenticate('ADMIN', '') | |
AppUser Load (0.9ms) EXEC sp_executesql N'SELECT TOP (1) [AppUsers].* FROM [AppUsers] WHERE [AppUsers].[UserID] = N''ADMIN'' AND [AppUsers].[Password] = N'''' ORDER BY [AppUsers].[UserID] ASC' | |
=> #<AppUser UserID: "ADMIN", UserName: "Administrator", MenuGroup: "SYS_ADMIN", Password: "", DefaultStoreID: "1", FullRights: true, LastChanged: "2013-10-23 17:59:52", ChangedBy: "ADMIN", Email: "", Phone: "", Deleted: false, CashierID: "", HideCostPrice: false, WebLogin: false, CustomerID: "", DepID: "", NetworkID: ""> |
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
search_all = LOCAL_SETTINGS["single_site_search"] | |
if params[:ref].present? | |
spaces = Space.where(id: { params[:ref] }, parent_id: nil }) | |
spaces = spaces.eager_loads(slots: :companies).where(companies: { parent_id: current_company_id }) unless search_all | |
render partial: 'call_centre_results' and return | |
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
irb(main):001:0> module Foo | |
irb(main):002:1> def the_var(var) | |
irb(main):003:2> @var ||= var | |
irb(main):004:2> end | |
irb(main):005:1> end | |
=> nil | |
irb(main):006:0> class Bar | |
irb(main):007:1> end | |
=> nil | |
irb(main):008:0> Bar.extend(Foo).the_var("something") |
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
irb(main):043:0> '2X 2T6", "province"'.bytes | |
=> [50, 88, 32, 50, 84, 54, 226, 128, 142, 34, 44, 32, 34, 112, 114, 111, 118, 105, 110, 99, 101, 34] | |
irb(main):044:0> '2X 2T6", "province"'.bytes | |
=> [50, 88, 32, 50, 84, 54, 34, 44, 32, 34, 112, 114, 111, 118, 105, 110, 99, 101, 34] |
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 SelectedDoorkeeperFor < DoorkeeperFor | |
def initialize(*args) | |
options = args.pop if args.last.is_a? Hash | |
super(options) | |
only(args) | |
end | |
private | |
def only(actions) |
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
# Variable substitution works here | |
foo: "The quick brown %{ animal } jumped over the lazy dog" | |
# Variable substitution done not work here | |
# Instead, "%{ animal }" gets rendered | |
bar: "The quick | |
brown %{ animal } | |
jumped over | |
the lazy dog" |
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 update_status | |
order_statuses = self.rows.joins(row_status: :order_status).group('order_status.id').pluck('order_status.id') | |
self.order_status_id = order_statuses.one? ? order_statuses.pop : OrderStatus.find_by(name: "processing").id | |
self.save! | |
end |