Skip to content

Instantly share code, notes, and snippets.

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.
# 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 embed(youtube_url)
content_tag(:iframe, nil, src: youtube_url)
end
@norbajunior
norbajunior / .bash_profile
Last active August 29, 2015 14:26 — forked from cajun-code/.bash_profile
bash profile for rails development
source /usr/local/git/contrib/completion/git-completion.bash
complete -C "/usr/bin/gemedit --complete" gemedit
export WORKON_HOME=~/.env
export JAVA7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home
export JAVA6_HOME=/Library/Java/Home
export JAVA_HOME=$JAVA6_HOME
export PATH=$JAVA_HOME/bin:$PATH
export SBT_OPTS="-XX:MaxPermSize=256M"
@norbajunior
norbajunior / 0_user_account.rb
Last active August 29, 2015 14:26
Estrutura de Serviço de Conta de Usuário
class UserAccount
include LinkWithFacebook
include LinkWithTwitter
include SignUpWithFacebook
include SignUpWithTwitter
def initialize(params)
@user_params = params[:user]
@social_params = params[:social]
end
MedicalCare
.select([
MedicalCare.arel_table[:created_at],
MedicalCare.arel_table[:triage_entrance_id],
Sigtap::Occupation.arel_table[:name],
Person.arel_table[:name].as('person_name'),
Person.arel_table[:mother].as('person_mother'),
Person.arel_table[:birthdate].as('person_birthdate'),
])
.joins(:occupation, patient: :person)
class Patient::Entrance < Salus::Model
# ja tinha no model
has_many :medical_cares, foreign_key: :patient_entrance_id
# ja tinha no model
has_one :first_medical_care,
class_name: 'MedicalCare',
foreign_key: :patient_entrance_id,
order: MedicalCare.arel_table[:id].asc
@norbajunior
norbajunior / doc.md
Created July 15, 2016 16:57 — forked from oelmekki/doc.md
Rails + Browserify + React + es7

1. Gemfile

gem 'browserify-rails', '1.5.0' # until fix: https://github.com/browserify-rails/browserify-rails/issues/101
gem 'react-rails'

Browserify-rails allows to use browserify within assets pipeline. React-rails is here only to allow to use #react_component (and thus, prerendering).

Note that jquery-rails can be removed from Gemfile, the npm version of jquery and jquery-ujs will be used instead.

class RadioOption extends React.Component {
static propTypes = {
label: React.PropTypes.string.isRequired,
inputHtml: React.PropTypes.object,
wrapperHtml: React.PropTypes.object,
labelHtml: React.PropTypes.object,
labelAttribute: React.PropTypes.string,
idAttribute: React.PropTypes.string,
disableOptions: React.PropTypes.array,
options: React.PropTypes.array
@norbajunior
norbajunior / form_steps.rb
Created July 28, 2016 10:32 — forked from emk/form_steps.rb
Fill in multiline forms with Cucumber and Webrat
# Fill in multiple form fields using a table. Use it as follows:
#
# When I fill in the fields
# | Field 1 | Value 1 |
# | Field 2 | Value 2 |
When /^I fill in the fields$/ do |table|
table.rows_hash.each {|field, value| fill_in field, :with => value }
end