Skip to content

Instantly share code, notes, and snippets.

@TiagoTi
TiagoTi / controller.rb
Created March 18, 2015 15:12
atrr_manual.face
class YourController < ApplicationController
def new
@model = YourModel.new
end
def create
#set from the views
@model = YourModel.new(params[:model])
#set manual
@model.anything= '...'
@TiagoTi
TiagoTi / v1 file 1 config_initializers_pagseguro.rb
Last active August 29, 2015 14:16
Configuração PagSeguro Ruby
I18n.locale='pt-BR'
PagSeguro.configure do |c|
c.token= 'X89X78XX72034XX7XXXC6X73X146978X'
c.email= '[email protected]'
end
@TiagoTi
TiagoTi / 0-song.rb
Last active August 29, 2015 14:15
RestFull Routes and Templeates Slim With DataMapper
class Song
include DataMapper::Resource
property :id, Serial
property :title, String
property :lyrics, Text
property :length, Integer
property :released_on, Date
def released_on=date
super Date.strptime(date, '%m/%d/%Y')
end
require 'sinatra'
require 'warden'
class YourApp < Sinatra::Application
get "/" do
erb 'index'.to_sym
end
get "/protected_pages" do
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
require "minitest/autorun"
require_relative "../lib/conversor_de_numero_romano.rb"
class TestConversorDeNumeroRomano < MiniTest::Unit::TestCase
def teste_deve_entender_o_simbolo_I
romano = ConversorDeNumeroRomano.new
numero = romano.converte 'I'
assert_equal 1, numero
end

Useful commands

last_response
    .body

last_request
    .path
    .url
    .session

.cookies