Skip to content

Instantly share code, notes, and snippets.

View ricoSaw's full-sized avatar

Rico Schulz ricoSaw

View GitHub Profile
@ricoSaw
ricoSaw / gist:abd598a841f264649c62
Created January 28, 2016 10:47
builds the dynamic form and fills with data via JavaScript
$(document).ready(function () {
// click event-listener for discounted link
$('#marketing-discounted-link').click(function(){
// data from data attributes
var data = $('#marketing-discounted-data').data();
var url = $(this).attr('href');
var dynForm = buildForm(data, url);
dynForm.submit();
@ricoSaw
ricoSaw / rvm_hook_for_JRUBY_OPTS
Last active December 23, 2015 23:49
Setting JRUBY_OPTS in rvm after_use HOOK
# insert JRUBY_OPTS in
# /home/your_home_directory/.rvm/hooks/
# in file "after_use_jruby"
JRUBY_OPTS="-J-Xmx1024m -J-XX:MaxPermSize=512m " ; export JRUBY_OPTS
@ricoSaw
ricoSaw / gist:6341596
Created August 26, 2013 13:48
begin rescue ensure blocks
begin
# something which might raise an exception
rescue SomeExceptionClass => some_variable
# code that deals with some exception
rescue SomeOtherException => some_other_variable
# code that deals with some other exception
else
# code that runs only if *no* exception was raised
ensure
# ensure that this code always runs, no matter what
@ricoSaw
ricoSaw / gist:5060229
Last active December 14, 2015 08:49
# Möglichkeit 2 Wohl die bessere Lösung mit inverse_of und validates_associated.
class Plan < ActiveRecord::Base
...
has_many :plan_additions, :inverse_of => :plan
validates_associated :plan_additions
accepts_nested_attributes_for :plan_additions
...
@ricoSaw
ricoSaw / gist:5060023
Last active December 14, 2015 08:48
# Möglichkeit 1 Die Validierung aus den plan_addition in plan zu verlagern
class Plan < ActiveRecord::Base
has_many :plan_additions
...
after_validation do
plan_additions.each do |plan_addition|
# hier könnte eine andere, bessere Validierung in plan_addition model gepackt werden
if plan_addition.monthly_price.blank?
plan_addition.errors.add(:monthly_price, :blank)