Skip to content

Instantly share code, notes, and snippets.

Controller:
def index
@site = Site.new
@todos_sites = Site.all
end
View:
<% @todos_sites.each do |site| %>
Test Line
<% end %>
C:\Projetos\steste>rake spec
(in C:/Projetos/steste)
C:/Ruby192/bin/ruby.exe -S bundle exec rspec "./spec/helpers/home_helper_spec.rb
"
F
Failures:
1) HomeHelper check ret_true helper
Failure/Error: helper.ret_true.should be_false
expected true to be false
@pnegri
pnegri / application_controller.rb
Created February 24, 2011 01:19
Trying to do a DRY multi tenancy with mongoid
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter do
# Find Account_ID by seach for a domain - NOT Refactored yet
host_id = $memcache_instance.get('hosts/' + request.host)
unless host_id
host_db_row = BimbooHost.where( :host => request.host ).one
if host_db_row
$memcache_instance.set('hosts/' + request.host, host_db_row.bimboo_account_id, 60*60)
@pnegri
pnegri / original.rb
Created February 24, 2011 02:56
what a better way to do this?
def set_account_id
return false if BimbooAccount.current.nil?
self.bimboo_account_id = BimbooAccount.current._id
end
module ApplicationHelper
def configurar_pedido(pedido)
returning(pedido) do |p|
p.iteracoes.build if p.iteracoes.empty?
end
end
end
Adicionar um metodo no dashboard (config.php), e criar uma rota.
O metodo vai conter
function getting_started( $params )
{
print file_get_contents("http://www.bimboo.com.br/...");
return true;
}
// adicionar a rota, ex /admin/bimboo_getting_started
class mobile_detector_controller
{
function classico($params) {
global $build_page_cache,$expiration_date; // Acessar globais de geração de Cache
// Desabilitar cache para url
$build_page_cache = false; $expiration_date = 0;
// Setar Cookie 'ignorarMobile' com valor 1
web::cookie_set_variable('ignorarMobile',1,time()+(60*60*24*365));
<script type="text/javascript">
window.addEvent('domready', function() {
if (Cookie.read('ignoreMobile') != 1) {
if( navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPod/i)
){
it "should be readonly after find if locked equals true" do
@log = Fabricate(:invoice_log_locked)
lambda {
@locked_log = InvoiceLog.where(:locked => true).first()
@locked_log->description = "Changing the Description"
@locked_log->save()
}.should raise_error(ActiveRecord::ReadOnlyRecord)
end
@pnegri
pnegri / damn-spaghetti.coffee
Created February 24, 2012 17:16
Developing an Approach to Javascript Spaghetti
Fs = require 'fs'
Path = require 'path'
Flow = require 'async'
class TestingSomething
organize_basket: ( next_callback ) ->
@basket = {}
next_callback null