Skip to content

Instantly share code, notes, and snippets.

View novohispano's full-sized avatar

Jorge Téllez novohispano

View GitHub Profile
class ItemsController < ApplicationController
def index
@items = Item.all
respond_to do |format|
format.html { @items }
format.json { render json: @items }
format.xml { render xml: @items }
end
end
@novohispano
novohispano / item.rb
Created May 29, 2015 20:29
Rails Testing
class Item < ActiveRecord::Base
validates :name, presence: true
end
@novohispano
novohispano / _navbar.html.rb
Created May 18, 2015 07:34
Multitenant Storedom
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button class="navbar-toggle" data-target="#bs-example-navbar-collapse-1" data-toggle="collapse" type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Storedom</a>
</div>
@novohispano
novohispano / deploy.rake
Created May 5, 2015 07:55
Rake task to deploy to Heroku
desc "Print name"
task :name, [:name] do |t, arguments|
puts "My name is #{arguments[:name]}"
end
desc "Favorite animal"
task :animal, [:animal] do |t, arguments|
puts "My favorite animal is #{arguments[:animal]}"
end
@novohispano
novohispano / account_presenter.rb
Created April 21, 2015 12:31
Decorators & Presenters
class AccountPresenter
extend Forwardable
attr_reader :account
def_delegators :account, :amount, :created_at
def initialize(account)
@account = account
end
class Seed
def initialize
generate_users
generate_items
generate_orders
end
def generate_users
50.times do |i|
user = User.create!(
@novohispano
novohispano / application.yml
Last active August 29, 2015 14:16
Getting Started with OAuth
development:
github_key: 710899dd3710a6a9814e
github_secret: 102dc5253ae360eaae533e7dc5ceb46929dcbe4b
@novohispano
novohispano / application_helper.rb
Created February 18, 2015 11:45
Caching in Rails
module ApplicationHelper
def cache_key_for(model)
prefix = model.to_s.downcase.pluralize
count = model.count
max_updated_at = model.maximum(:updated_at).try(:utc).try(:to_s, :number)
"#{prefix}/all-#{count}-#{max_updated_at}"
end
end
@novohispano
novohispano / deploy.rake
Created January 26, 2015 17:01
Rake task for Heroku deployment.
namespace :deploy do
desc "Deploys app to Github & production."
task all: :environment do
if system("rake test:all") == false
puts "The tests fail."
break
end
puts "The tests passed."
@novohispano
novohispano / routes.rb
Last active August 29, 2015 14:11
Multitenant Blogger Advanced.
# Original Router
Rails.application.routes.draw do
resources :articles
resources :comments
resource :account, only: [:show] do
get :work
end
get '/login' => 'sessions#new'