This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
046dca3a09c346963ddf89277262c01ed071e89833b5dd8474466bfb7c99150494fd416de41238335440b30da8f4d47a3866a144674a8f21eda81c137407093171;effektz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "thread" | |
class Future | |
attr_reader :exception, :cancelled | |
def initialize(&block) | |
@thread = Thread.new(&block) | |
@thread.abort_on_exception = false | |
@exception = nil | |
@cancelled = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sprockets::Helpers::RailsHelper | |
require File.join(Rails.root, "app", "helpers", "assets_helper.rb") | |
include AssetsHelper | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
# We are not loading Active Record, nor Active Resources etc. | |
# We can do this in any app by simply replacing the rails gem | |
# by the parts we want to use. | |
gem "actionpack", "~> 3.2" | |
gem "railties", "~> 3.2" | |
gem "tzinfo" | |
# Let's use thin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ActionController::Base | |
def create | |
Post.create(post_params) | |
end | |
def update | |
Post.find(params[:id]).update_attributes!(post_params) | |
end | |
private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
</head> | |
<body> | |
<div class="draggable" style="width: 50px; float: left; height: 50px; background: red;">1</div> | |
<div class="draggable" style="width: 50px; float: left; height: 50px; border: 1px solid red;">2</div> | |
<div class="draggable" style="width: 50px; float: left; height: 50px; border: 1px solid red;">3</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Popup | |
def make | |
"Making from instance" | |
end | |
def self.make | |
"Making from class" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Controller | |
def stats | |
@visits = Visit.all | |
end | |
## View that produces 2 sql hits | |
<%= @visits[0] %> | |
<% @visits.each do |v| %> | |
... | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails 3 + DM 0.10.0 | |
>> User.count | |
NoMethodError: undefined method `aggregate' for #<DataMapper::Adapters::MysqlAdapter:0xb77b7cc8> | |
from /home/justin/apps/rails/blog/vendor/gems/gems/dm-aggregates-0.10.0/lib/dm-aggregates/repository.rb:5:in `aggregate' | |
from /home/justin/apps/rails/blog/vendor/gems/gems/dm-aggregates-0.10.0/lib/dm-aggregates/aggregate_functions.rb:166:in `aggregate' | |
from /home/justin/apps/rails/blog/vendor/gems/gems/dm-aggregates-0.10.0/lib/dm-aggregates/aggregate_functions.rb:38:in `count' | |
from (irb):39 | |
>> User.aggregate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Problem: With a form_for in Rails 3, it checks object.errors['field'].any? | |
which in DataMapper returns nil if no errors are found, | |
in ActiveRecord it returns an empty array. | |
<% form_for @user, :url => "/users" do |f| %> | |
<%= f.text_field :login %> | |
<% end %> | |
You have a nil object when you didn't expect it! | |
You might have expected an instance of Array. |
NewerOlder