Skip to content

Instantly share code, notes, and snippets.

View aneziocampos's full-sized avatar

Anezio Marques de Campos Junior aneziocampos

  • Bonsai
  • Londrina, Paraná, Brasil
View GitHub Profile
<html>
<h1>Teste</h1>
</html>
[aneziocampos] portal (master) $ rvm install ruby-1.8.7-p374
Warning! PATH is not properly set up, '/Users/aneziocampos/.rvm/gems/ruby-2.2.0/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.2.0'.
Warning, new version of rvm available '1.27.0', you are using older version '1.26.11'.
You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.11/x86_64/ruby-1.8.7-p374.
Cuidados com Observer e callbacks
Já foi divulgado que na versão 4 do Rails estará sendo removido o Observer e ele deverá ser utilizado como uma gem. Estive analisando em alguns projetos a utilização dessa classe e as vezes encontro situações onde acredito que ela pode estar fazendo mais mal do que bem para o projeto.
A grosso modo a utilização de Observer nada mais é do que uma extração de código dos callbacks, ou seja, é necessário também muito cuidado ao ser utilizado para não exagerar na lógica que é colocada nela, o que pode gerar comportamentos não desejados da classe, além de aumentar a complexidade nos testes onde a gente acaba tendo que mockar/implementar funcionalidades extras do que realmente está querendo ser testado.
Um exemplo dessa situação é o Welcome email que é enviado quando um usuário é cadastrado.
class UserObserver < ActiveRecord::Observer
def after_create(user)
class PostsController < ApplicationController
before_filter :authenticate_user!
before_filter :load_post_and_project, except: :create
respond_to :html, :js
def create
@post = current_user.posts.new(params[:post])
@post.save
@project = @post.project
if @project.user == current_user
class AuthorizationsController < ApplicationController
before_filter :require_user, :only => [:destroy]
def create
omniauth = request.env['omniauth.auth'] #this is where you get all the data from your provider through omniauth
@auth = Authorization.find_from_hash(omniauth)
if omniauth['provider'] == 'stripe_platform'
current_user.stripe_token = omniauth[:credentials][:token]
current_user.stripe_publishable_key = omniauth[:extra][:raw_info][:stripe_publishable_key]
current_user.save
!!!
%html{:lang => "pt-br"}
%head
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
%link{:href => "css/style.css", :media => "all", :rel => "stylesheet", :type => "text/css"}
%title pagkom - Pagamentos Online
%body
/ Section geral do HTML5 - Contem todo o corpo do HTML
%section.general
/ Header principal do HTML5 - Contem o cabeçalho so site, incluindo o menu superior