Skip to content

Instantly share code, notes, and snippets.

View derencius's full-sized avatar
🍀
Wish me luck, I'm fixing my bugs

Marcus Derencius derencius

🍀
Wish me luck, I'm fixing my bugs
  • Ubatuba, São Paulo, Brazil
View GitHub Profile
<%= form_for(@stake) do |f| %>
<% if @stake.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@stake.errors.count, "error") %> prohibited this stake from being saved:</h2>
<ul>
<% @stake.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
def create
erros = []
variants = []
ProductionLabel.transaction do
begin
label = ProductionLabel.create!(params[:production_labels])
unless (label.valid?)
raise label.errors.full_messages
end
@derencius
derencius / utf8_header.rb
Created February 3, 2011 19:05 — forked from francesc/utf8encode.rake
thor file to add utf-8 header on ruby files. useful for converting ruby 1.8 projects to 1.9
class Utf8Header < Thor
desc "add", "Add Content UTF-8 on top of all .rb/.feature files"
# copy & pasted from https://gist.github.com/738245
def add
files = Array.new
["*.rb", "*.rake","*.feature"].each do |extension|
files.concat(Dir[ File.join(Dir.getwd.split(/\\/), "**", extension) ])
end
files.each do |file|
# add this file as config/initializers/will_paginate_postgresql_count.rb
# in a Rails application
module WillPaginate
module Finder
module ClassMethods
# add '1=1' to paginate conditions as marker such that the select from the pg_class
# is used to approximate simple rows count, e.g.
# Foo.paginate(:page => params[:page], :conditions => "1=1")
module MultiParameterAttributes
def filter_time(attributes, name)
attrs = attributes.collect do |key, value|
if key =~ /^#{Regexp.escape(name.to_s)}\((\d+)(\w)\)$/
[$1.to_i, value.send("to_#$2")]
end
end.compact.sort_by(&:first).map(&:last)
Time.zone.local(*attrs) unless attrs.empty?
end
class Address
include Mongoid::Document
belongs_to :user, :inverse_of => :addresses
belongs_to :venue, :inverse_of => :venues
field :street, :type => String
field :city, :type => String
field :state, :type => String
field :zip, :type => Integer
@derencius
derencius / mongoid-heroku.rb
Created May 7, 2010 04:53 — forked from ivanacostarubio/mongoid-heroku.rb
rails3 mongoid template
file 'Gemfile', <<-GEMS
source 'http://gemcutter.org'
gem "rails", "3.0.0.beta3"
gem "bson_ext"
gem "mongoid", "2.0.0.beta4"
gem "haml", "3.0.0.rc.2"
gem "compass", "0.10.0.rc4"
gem "inherited_resources"
group :test do
#!/bin/bash
# run with: curl -s http://gist.github.com/265272.txt | bash
set -e
localdir=$HOME/.mongodb
datadir=$localdir/data
conf=$localdir/mongod.conf
agentdir=$HOME/Library/LaunchAgents
agent=$agentdir/org.mongodb.mongod.plist
Rails CMS alternatives
======================
Active projects:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
"the cutting edge Rails CMS platform"