Skip to content

Instantly share code, notes, and snippets.

def do_something_with_post(post) # what you write as (post) here is the same as |post| in a block
puts post
end
do_something_with_post(1) # will print 1
@Hakon
Hakon / env.rb
Created May 20, 2011 13:21
cucumber rail engine dummy testing
require 'rails'
require 'cucumber/rails3/application'
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../spec/dummy/config/environment')
require 'cucumber/rails3/action_controller'
if defined?(ActiveRecord::Base)
@Hakon
Hakon / additional notes
Created August 14, 2011 14:49
restrict deleting/updating to signed in users
I have a session variable that is created on login called current_user i can access the company id and user id by calling the following: current_user.company_id and current_user.id
# this one does NOT work
params[:wine] = {:bulk_price_per_dozen => 50}
@wine = Wine.new(params[:wine])
# this one ALSO does NOT work
@wine = current_seller.wines.build(params[:wine])
# this one does work
@wine = current_seller.wines.build
@wine.attributes = params[:wine]
@Hakon
Hakon / _form.html.erb
Created September 5, 2011 07:11 — forked from vjm/_form.html.erb
CRUD Devise Example
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
# encoding: utf-8
require "json"
# Expected (and MRI behavior):
str = JSON.parse('{"a":"\u00f8"}')["a"]
str == "ø"
str.encoding.to_s == "UTF-8"
# Actual (jruby behavior):
@Hakon
Hakon / rackup.ru
Created May 22, 2012 18:39
Jruby-rack with rails send_file bug
%w(action_controller/railtie).map &method(:require)
run JrubyRackTest ||= Class.new(Rails::Application) {
config.secret_token = routes.append { root to: 'send_file#deliver' }.inspect
initialize!
}
class SendFileController < ActionController::Base
def deliver
send_file Rails.root.join("testdata.jpeg")
object with tag: 10 and value: 2 and val.class: org.jruby.RubyFixnum and impl: org.bouncycastle.asn1.DEREnumerated
WARNING: unimplemented method called: asn1data#toASN1
require 'openssl'
blk = "0)\x02\x01\x01`$\x02\x01\x03\x04\x17cn=admin,dc=test,dc=com\x80\x06secret"
asn1 = OpenSSL::ASN1::decode(blk)
protocolOp = asn1.value[1]
puts protocolOp.inspect
ActionView::Template::Error (Java heap space):
java.nio.HeapCharBuffer.<init>(HeapCharBuffer.java:39)
java.nio.CharBuffer.allocate(CharBuffer.java:312)
java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:775)
java.nio.charset.Charset.decode(Charset.java:771)
org.jruby.RubyEncoding$UTF8Coder.decode(RubyEncoding.java:246)
org.jruby.RubyEncoding.decodeUTF8(RubyEncoding.java:192)
org.jruby.RubyString.decodeString(RubyString.java:719)
org.jruby.RubyString.toString(RubyString.java:701)
org.jruby.RubyNameError$RubyNameErrorMessage.to_str(RubyNameError.java:120)