Skip to content

Instantly share code, notes, and snippets.

View Sanchezdav's full-sized avatar
🏠
Working from home

David Sanchez Sanchezdav

🏠
Working from home
View GitHub Profile
@chsh
chsh / orders_controller_spec.rb
Created April 30, 2013 13:35
RSpec controller example
require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
@mlanett
mlanett / rails http status codes
Last active July 22, 2024 09:14
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
@esteedqueen
esteedqueen / authenticable.rb
Last active December 7, 2022 08:52 — forked from Bomadeno/registrations_controller.rb
JSON API User Registration and Sessions with Devise
module Authenticable
# Devise methods overwrite
def current_user
@current_user ||= User.find_by(authentication_token: request.headers['Authorization'])
end
def authenticate_with_token!
render json: { errors: "Not authenticated" },
status: :unauthorized unless user_signed_in?
@pioz
pioz / engines.md
Created August 29, 2019 14:48
Using webpacker inside a Rails engine

Using in Rails engines

If the application UI consists of multiple frontend application, you'd probably like to isolate their building too (e.g. if you use different frameworks/versions). Hence we needed our webpack(-er) to be isolated too: separate package.json, dev server, compilation process.

You can do this by adding another Webpacker instance to your application.

This guide describes how to do that using Rails engines.

Step 1: create Rails engine.

@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active July 18, 2024 16:00
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias