Skip to content

Instantly share code, notes, and snippets.

View jpzwarte's full-sized avatar

Jeroen Zwartepoorte jpzwarte

View GitHub Profile
@jpzwarte
jpzwarte / behaviors.js.coffee
Created October 12, 2012 08:55
jquery_ujs async confirm
$ ->
$.rails.confirm = (message) ->
answer = $.Deferred();
modal = $ """
<div class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Delete</h3>
</div>
@jpzwarte
jpzwarte / index.html
Created June 18, 2012 12:18 — forked from fpauser/index.html
Ember.Router
<!doctype html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript' src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script type='text/javascript' src="http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js"></script>
</head><body>
<script type="text/x-handlebars" data-template-name="application">
<h1>Application</h1>
<a href="#/dashboard">Dashboard</a>
@jpzwarte
jpzwarte / test.rb
Created November 14, 2011 08:23
Failing test
1) Error:
test_coerced_test_delete_all_with_join(DeleteAllWithJoinTest):
ActiveRecord::StatementInvalid: TinyTds::Error: The multi-part identifier "posts.author_id" could not be bound.: EXEC sp_executesql N'DELETE FROM [people] WHERE [posts].[author_id] IS NULL; SELECT @@ROWCOUNT AS AffectedRows'
@jpzwarte
jpzwarte / capybara_webkit_screenshot_env.rb
Created August 23, 2011 13:52 — forked from mattheworiordan/capybara_webkit_screenshot_env.rb
Cucumber and Capybara-Webkit automatic screenshots on failure
def screen_shot_and_save_page
require 'capybara/util/save_and_open_page'
path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
Capybara.save_page body, "#{path}.html"
page.driver.render Rails.root.join "#{Capybara.save_and_open_page_path}" "#{path}.png"
end
begin
After do |scenario|
screen_shot_and_save_page if scenario.failed?
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
diff --git a/lib/inherited_resources/base_helpers.rb b/lib/inherited_resources/base_helpers.rb
index ccdf7ae..e94d875 100644
--- a/lib/inherited_resources/base_helpers.rb
+++ b/lib/inherited_resources/base_helpers.rb
@@ -73,6 +73,15 @@ module InheritedResources
#
def update_resource(object, attributes)
object.update_attributes(attributes)
+ attributes.keys.each do |key|
+ key.match(/^(?<association_name>\w+)_attributes$/)
diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb
index c8e8e22..4610f7c 100644
--- a/lib/simple_form/form_builder.rb
+++ b/lib/simple_form/form_builder.rb
@@ -242,6 +242,11 @@ module SimpleForm
SimpleForm::ErrorNotification.new(self, options).render
end
+ def wrapper(css_class, &block)
+ options[:wrapper_class] = css_class.to_s
ruby-1.9.2-p0 > s = Site.first
EXECUTE (0.6ms) USE [mpp_admin_dev]
Site Load (0.4ms) SELECT TOP (1) [sites].* FROM [sites]
=> #<Site id: 1, domain_id: nil, content_id: nil, name: "realtime", course_name: nil, ga_code: nil, webshop_url: nil, created_at: "2010-12-08 12:12:41", updated_at: "2010-12-08 12:38:08", published_at: nil, deleted_at: nil>
ruby-1.9.2-p0 > s.name = 'realtime2'
=> "realtime2"
ruby-1.9.2-p0 > s.save
EXECUTE (0.5ms) BEGIN TRANSACTION
EXECUTE (1.0ms) UPDATE [sites] SET [name] = N'realtime2', [updated_at] = '2010-12-08 12:57:50.514' WHERE ([sites].[id] = 1)
{"content_id"=>nil, "course_name"=>nil, "created_at"=>2010-12-08 12:12:41 UTC, "domain_id"=>nil, "ga_code"=>nil, "name"=>"realtime2", "updated_at"=>2010-12-08 12:57:50 UTC, "webshop_url"=>nil}
$(document).ready(function() {
// Define the dateFormat for the datepicker
$.datepicker._defaults.dateFormat = 'dd M yy';
/**
* Sets the date for each select with the date selected with datepicker
*/
$('input.ui-date-text').live("change", function() {
var sels = $(this).siblings("select:lt(3)");
var d = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $(this).val() );
def teacher_plus?(level)
products.first(
:joins => :levels,
:conditions => [ "(licenses.expires_at > ?) AND domains.id = ?", Time.now.to_date, level ],
:order => "products.product_type DESC").try(:product_type) == 'teacher_plus'
end