Skip to content

Instantly share code, notes, and snippets.

def embed(youtube_url)
content_tag(:iframe, nil, src: youtube_url)
end
# app/business/concert/update.rb
# Concert::RescheduleEmail.sent(concert, new_time)
class Concert::RescheduleEmail
def self.sent(concert, new_time)
new(concert, new_time).sent
end
def initialize(concert, new_time)
@concert, @starts_at = concert, new_time.to_time
def update
if @concert.update(params[:concert])
@concert.confirm!
redirect_to user_concert_path(current_user, @concert), notice: t('flash.concerts.update_success')
else
@top_tippers = ConcertPayment.top_tippers(@concert).limit(5) # isso daqui dá pra melhorar, chamar @concert.top_tippers é mais legível
@concert_payments = @concert.concert_payments # se não for usar na view, nao precisa ser variavel de instancia esse @concert_payments
@amount = @concert_payments.amount # => faz scope disso map(&:amount).sum, sem usar os métodos do ruby. Faça um sql.
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
model.send("#{association}_attributes=".to_sym,[@reject])
@reject_success = model.send("#{association}").empty?
end
model.send("#{association}").clear

Emoji Spec

results Tired of the same, dull rspec output? liven it up with some emoji!

Below are the sets presently available, and their corresponding id. if you don't set an ID, one will be randomly chosen every run. Emoji icons may not render in certain terminals.

(pass, fail, pending)

emoji

# RemoveAccents version 1.0.3 (c) 2008-2009 Solutions Informatiques Techniconseils inc.
#
# This module adds 2 methods to the string class.
# Up-to-date version and documentation available at:
#
# http://www.techniconseils.ca/en/scripts-remove-accents-ruby.php
#
# This script is available under the following license :
# Creative Commons Attribution-Share Alike 2.5.
#
@norbajunior
norbajunior / syntax_highlighting.py
Created December 14, 2011 13:05 — forked from JeanMertz/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@norbajunior
norbajunior / syntax_highlighting.py
Created December 13, 2011 21:07 — forked from JeanMertz/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@norbajunior
norbajunior / roteiro.md
Created December 7, 2011 14:27 — forked from danielvlopes/roteiro.md
Roteiro Aula 6 - Una Web 2

Apagar action show de skills_controller.rb

Em application.html.erb alterar o menu para:

-    <li><%= link_to "Skills", skills_path %></li>

Remover indicações de profile nas views de Skills:

-    <th>Profile</th>
  • <%= skill.profile %>
@norbajunior
norbajunior / roteiro-aula5.md
Created December 7, 2011 14:26 — forked from danielvlopes/roteiro-aula5.md
Roteiro aula 5 - Una Web 2