Skip to content

Instantly share code, notes, and snippets.

View joseh-henrique's full-sized avatar

Joseh-Henrique joseh-henrique

View GitHub Profile
@joseh-henrique
joseh-henrique / ability.rb
Created September 4, 2012 19:06 — forked from andrerpbts/ability.rb
Menus SGO
#encoding: utf-8
class Ability
include CanCan::Ability
def initialize(user)
user.perfis.each do |perfil|
perfil.permissoes_perfis.each do |permissao|
can permissao.acao.to_sym, Recurso.por_tipo(permissao.recurso, permissao.tipo)
end
end
@joseh-henrique
joseh-henrique / activeadmin-cancan.rb
Created November 12, 2012 11:00 — forked from mrichie/activeadmin-cancan.rb
Deep integration of CanCan into ActiveAdmin
# blog post:
# Before using this initializer, you must set up Cancan. First, add the gem to your Gemfile:
#
# gem 'cancan'
#
# Next, generate and edit an Ability class:
#
# rails generate cancan:ability
#
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
StringInput
TextInput
@joseh-henrique
joseh-henrique / searching.rb
Created October 7, 2015 13:53 — forked from xdougx/searching.rb
A intenção era só simplificar e ganhar todos os métodos sem precisar fazer muito, é muito simples fazer em uma classe desprendida do ActiveRecord
module Searchable
included do
scope :gender, ->(gender) { where(:gender => gender) }
scope :birth_on, ->(date) { where(:birthdate =>date) }
scope :birth_before_than, ->(date) { where("#{quoted_table_name}.birthdate < ?", date) }
scope :birth_after_than, ->(date) { where("#{quoted_table_name}.birthdate > ?", date) }
scope :profile, ->(profile){ where(:profile => profile) }
end
module ClassMethods
@joseh-henrique
joseh-henrique / 01_sponsor.rb
Created November 16, 2016 16:37 — forked from jonathanccalixto/01_sponsor.rb
Criando um FormFilter no rails
# Este aquivo fica em app/models/sponsor.rb
class Sponsor < ActiveRecord::Base
# aqui fica meu codigo e scopes
end
@joseh-henrique
joseh-henrique / _some_field.html.haml
Created January 6, 2017 22:33 — forked from manfe/_some_field.html.haml
Creating <optgroup> in select fields using simple_form
= f.association :cities, :collection => State.all, :as => :grouped_select,
:group_method => :cities, :group_label_method => :name
@joseh-henrique
joseh-henrique / rails_annotations.md
Created May 11, 2018 20:07 — forked from daltonjorge/rails_annotations.md
Explicações de conceitos do Rails e outras infos úteis.

Active Record

É um design pattern que o Rails implementa a partir da gem ActiveRecord.

Serve para conectar a camada Model da aplicação com tabelas do database, para assim criar um modelo de domínio persistível, onde a lógica (Model) e dados (BD) são apresentados em uma única solução.

Já persiste no BD:

obj.create
@joseh-henrique
joseh-henrique / tutorial.md
Created March 27, 2020 14:55 — forked from Hinsei/tutorial.md
Using Cloudinary With CarrierWave Rails

Uploading Files To A Cloud Via Cloudinary and CarrierWave with Rails

This is a tutorial on how to use Cloudinary cloud services with carrierwave to upload files, in this case we would like to use it for image uploading for our users avatar

Sign Up For A Cloudinary Account

Cloudinary -> Sign up for an account here!

Take Note Of Details In Your Dashboard

After successfuly signing up, you will be redirected to your dashboard.

@joseh-henrique
joseh-henrique / attachinary_setup.md
Created March 27, 2020 18:01 — forked from ssaunier/attachinary_setup.md
Attachinary Setup in Rails 5

Attachinary Setup

First add the following gems to your Gemfile:

# Gemfile
gem "attachinary"
gem "jquery-fileupload-rails"
gem "coffee-rails"
@joseh-henrique
joseh-henrique / active_admin.js
Created March 27, 2020 18:03 — forked from balvig/active_admin.js
Active Admin Cloudinary
# app / assets / javascripts / active_admin.js
//= require active_admin/base
//= require jquery.ui.widget
//= require jquery.iframe-transport
//= require jquery.fileupload
//= require cloudinary/jquery.cloudinary
//= require attachinary
//= require attachments