Skip to content

Instantly share code, notes, and snippets.

@xhoy
xhoy / console.rb
Created January 22, 2015 10:33
lost in translation
>> x = Phonenumber
=> Phonenumber(id: integer, phonenumber: string, location: string, comment: text, user_id: integer, holder_id: integer, holder_type: string, created_at: datetime, updated_at: datetime, disabled_at: datetime, disabled_by: integer, rank: integer)
>> t(x)
=> "<span class=\"translation_missing\" title=\"translation missing: nl.Phonenumber\">Phonenumber</span>"
>> t(x.name)
=> "<span class=\"translation_missing\" title=\"translation missing: nl.Phonenumber\">Phonenumber</span>"
>> t(x.name.downcase)
=> "<span class=\"translation_missing\" title=\"translation missing: nl.phonenumber\">Phonenumber</span>"
>> t("models.#{x.name.downcase}")
=> "Telefoonnummer"
BEFORE:
<div class="foo">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
AFTER:
<div class="foo">
<div class="newdiff">
<div class="bar"></div>
def new
@letter = Letter.new(letter_date: Date.today, draft: true)
@letter.message = render_to_string file: "letters/templates/default.txt.erb"
render :new
end
@xhoy
xhoy / ruby.rb
Created February 27, 2016 16:55
case and hash?
def random()
x = {a: "asf"}
case x
when :b
"foo"
when :a
"bar"
else
"fail"
end
DOES NOT WORK:
{% for invoice in relation.invoices.late %}
<tr>
<td>{{invoice.id}}</td>
<td>{{invoice.print_date}}</td>
<td>{{invoice.days_late}}</td>
<td>{{invoice.priceinbtw}}</td>
</tr>
{% endfor %}
Rails.application.routes.draw do
resources :comments
resources :articles do
#works
resources :comments
#works
resources :comments, only: :index
#broken??
resources :comments, only: :test #why doesn't this work?
end
app/models/invoice_payment.rb
class InvoicePayment < ActiveRecord::Base
def to_liquid
InvoicePaymentDrop.new(self)
end
end
app/drops/invoice_payment_drop.rb
class InvoicePaymentDrop < Liquid::Drop
delegate :days_late, :duedate, :priceinbtw, :priceexbtw, :print_date, :id, :late, :unpayed, to: :invoice
@xhoy
xhoy / console.rb
Created August 4, 2016 18:18
wtf? self != self
>> self
=> #<Activity id: 7126, user_id: 58, start_at: "2016-08-02 03:15:00", end_at: "2016-08-02 10:30:00", worked_hours: #<BigDecimal:7fda363efae0,'0.675E1',18(27)>, vacation_hours: #<BigDecimal:7fda363ef950,'0.51975E0',9(18)>, date: "2016-08-02", information: "othertest">
>> Activity.find(7126)
=> #<Activity id: 7126, user_id: 58, start_at: "2016-07-28 02:45:00", end_at: "2016-07-28 10:15:00", worked_hours: #<BigDecimal:7fda369f7bb8,'0.7E1',9(18)>, vacation_hours: #<BigDecimal:7fda369f7a50,'0.539E0',9(18)>, date: "2016-07-28", information: "test2">
Only clues:
@changed_attributes => {"id"=>7135}
@original_raw_attributes => {"id"=>7126}
# --
# Copyright (C) 2001-2016 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::GenericInterface::Invoker::Test::Test;
order = Order.new
#=> #<Order id: nil, created_at: nil, updated_at: nil, created_by: nil>
order.order_lines.new
# => #<OrderLine id: nil, product_id: nil, created_at: nil, updated_at: nil>
order.order_lines.last.order
#=> nil