Skip to content

Instantly share code, notes, and snippets.

View elissonmichael's full-sized avatar
🚫
undefined method 'status' for nil:NilClass

Élisson Michael elissonmichael

🚫
undefined method 'status' for nil:NilClass
View GitHub Profile
@mlanett
mlanett / rails http status codes
Last active June 14, 2024 06:07
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@joekur
joekur / html_safe.md
Last active December 11, 2023 22:57
Proper Use of `html_safe`

Proper use of html_safe

Let's look at an innocuous piece of ruby. Consider some view code showing a user's name and phone number:

"#{first_name} #{last_name} #{phone}"

Great - this is very succinct, readable, and can easily be extracted to a method in a

@psobocinski
psobocinski / dummy_controller.rb
Created January 23, 2016 20:04
Asserting on a JSON response in a Rails controller test with MiniTest
class DummyController < ApplicationController
def do
render json: { balance: 50 }
end
end
@dukeimg
dukeimg / expectation_matchers_spec.rb
Created February 28, 2016 09:13
RSpec -- Expectation Matchers
describe 'Expectation Matchers' do
describe 'equivalence matchers' do
it 'will match loose equality with #eq' do
a = "2 cats"
b = "2 cats"
expect(a).to eq(b)
expect(a).to be == b # synonym for #eq
@matiaskorhonen
matiaskorhonen / sign-pdf.rb
Last active May 25, 2023 10:58
Quick and dirty PDF signing in Ruby (using Origami)
#!/usr/bin/env ruby
require "openssl"
require "time"
begin
require "origami"
rescue LoadError
abort "origami not installed: gem install origami"
end
@the-bass
the-bass / application.html.erb
Last active April 15, 2020 15:01
Using Google Analytics with Rails 5 and Turbolinks 5. This code is taken from the conversation between @preetpalS and @packagethief on https://github.com/turbolinks/turbolinks/issues/73.
<%# Put this code snippet between the <head></head>-tags in your application layout and %>
<%# replace 'UA-XXXXXXXX-X' with your own unique Google Analytics Tracking ID %>
<%# ... %>
<head>
<%# ... %>
<% if Rails.env.production? %>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@claudiohilario
claudiohilario / Date Picker (materializecss) config pt pt.js
Created October 23, 2016 16:38
Tradução para português do Date Picker (materializecss)
$(function () {
//Config datepiker matrializecss () language
$('.datepicker').pickadate({
selectMonths: true,//Creates a dropdown to control month
selectYears: 15,//Creates a dropdown of 15 years to control year
//The title label to use for the month nav buttons
labelMonthNext: 'Proximo Mês',
labelMonthPrev: 'Mês Anterior',
//The title label to use for the dropdown selectors
labelMonthSelect: 'Selecionar Mês',
@robertpainsi
robertpainsi / commit-message-guidelines.md
Last active June 12, 2024 14:34
Commit message guidelines

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer
protected
@sephraim
sephraim / doubles_stubs_spies_spec.rb
Last active September 15, 2023 13:21
RSpec examples #rspec
# Sample reference code for doubles/mocks, stubs, and spies in RSpec
# Taken from Kevin Skoglund's RSpec tutorial on Lynda.com
describe 'Doubles' do
it "allows stubbing methods" do
dbl = double("Chant")
allow(dbl).to receive(:hey!)
expect(dbl).to respond_to(:hey!)
end