Skip to content

Instantly share code, notes, and snippets.

View jguitar's full-sized avatar

Juan F. Pérez jguitar

  • Barkibu
  • Valencia, Spain
View GitHub Profile
@cavalle
cavalle / cohesion-and-big-models.md
Last active December 11, 2015 21:09
Cohesion and Big ActiveRecord Models

Cohesion and Big ActiveRecord Models

One of the problems of big ActiveRecord models is their low cohesion. In Rails we group behaviour around the entities of the domain we're modelling. If we use only ActiveRecord models for that, we'll probably end up with classes full of actions, in most cases, completely unrelated to each other (except for the fact that they act on the same domain entity).

To illustrate the issue let's imagine a big Post AR model of a blog application. In this app, users can add tags to their posts. Since this is the only class with this ability, I decide to put the related logic in the Post model itself. For this, presumably at the beginning of the file, I write a couple of has_many entries for tags and taggings. Then, fifty lines below, along with the rest of scopes, I add one more to find posts by tag name. A couple of hundred lines later, I put a virtual attribute tag_list which will be used to update the associations from a string of tag names separated by commas. Fin

@linjunpop
linjunpop / Capybara-Rspec-Rails-assets-pipeline.md
Last active August 14, 2021 05:42
Capybara, Rspec, Rails assets pipeline
@equivalent
equivalent / README.md
Last active December 16, 2021 16:34
String "false" to_bool ... or how to convert Rails/SimpleForm radio buttons to boolean

This gist was writen in 2012 and it was solving specific problem in Rails & SimpleForm. Some fellow developers were pointing out this may be out dated concept. That's why I advise everyone to read comment section bellow to have a full grasp of alternative solutions

other sources that may be helpful to understand why this may not be best idea:

@andreareginato
andreareginato / Guardfile
Created October 2, 2012 16:49
Rails Guardfile (handle Spork and RSpec automatic tests)
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch(%r{^config/locales/.+\.yml$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
end
@andreareginato
andreareginato / spec_helper.rb
Created October 2, 2012 16:48
Rails Spec Helper (using Spork, Mongoid, Factory Girls, Draper, Webmock and Capybara)
require 'rubygems'
require 'spork'
# This code runs once when you run your test suite
Spork.prefork do
ENV['RAILS_ENV'] ||= 'test'
# Mongoid models reload
require 'rails/mongoid'
Spork.trap_class_method(Rails::Mongoid, :load_models)
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 23, 2024 18:01
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@Fernan2
Fernan2 / Excel.rb
Created May 24, 2012 11:09
Creación de Excels desde Rails
require 'spreadsheet'
include Spreadsheet
format.xls do
# ------ El bloque XLS debe ir sin paginación y con producto ------ #
fichero = "vila_#{@modo}_#{Time.now.to_f.to_s}.xls"
ruta = "#{Rails.root}/tmp/#{fichero}"
Spreadsheet.client_encoding = "UTF-8"
workbook = Spreadsheet::Workbook.new
@steveclarke
steveclarke / capybara.md
Created April 10, 2012 17:32
RSpec Matchers

Capybara

save_and_open_page

Matchers

have_button(locator)
@jexchan
jexchan / multiple_ssh_setting.md
Created April 10, 2012 15:00
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@jasoares
jasoares / gist:2217790
Created March 27, 2012 16:42
Ruby Exceptions Hierarchy
Object
+--Exception
+--NoMemoryError
+--ScriptError
| +--LoadError
| +--NotImplementedError
| +--SyntaxError
+--SecurityError # Was a StandardError in 1.8
+--SignalException
| +--Interrupt