Skip to content

Instantly share code, notes, and snippets.

@xhoy
xhoy / controller.rb
Last active January 24, 2018 12:08 — forked from anonymous/controller.rb
class UnApprovedActions < ApplicationController
def approve_action
Action.find_by(token: params[:token], *other stuff*).run_action
end
end
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
# --
# 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;
@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}
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
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
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 %}
@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
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
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>