Skip to content

Instantly share code, notes, and snippets.

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

Ruben Sierra rsierra

🏠
Working from home
View GitHub Profile
@brenes
brenes / model_with_attributes.rb
Last active December 15, 2015 11:29
Common shared examples for rspec
shared_examples_for "model with attributes" do |model_name|
context "validations" do
context "with valid values" do
let(:attributes) { attributes_for model_name }
let(:model_object) { build model_name, attributes }
subject { model_object }
@vortizhe
vortizhe / gist:4160170
Last active October 13, 2015 07:27
Debugger with pow and pry
# Remove all debug gems from your Gemfile and add
gem 'pry-remote'
# instead add interruption with debugger use
binding.remote_pry
# Use pry-remote in console and debug as you wish
@brenes
brenes / _README
Created August 27, 2012 12:02
How to solve Globalize3 issue with old migrations when adding translated fields
There's an issue on globalize when adding or removing fields from the translations that causes the original migrations don't work properly (https://github.com/svenfuchs/globalize3/issues/131).
In my example I have a post model whih I create with some translated fields: name, slug and body. Some days later, I realise I need an excerpt field with a summarized version of the post and it has to be translated, so I create a migration to add this field.
Unfortunately, when you create the translation table it takes not only the fields you set in the params (:name => :string, :slug => :string, :body => :text) but also the params specified to the translates method in the model (:excerpt included) and creates a column for each one of those.
Solution here is to overwrite the translated attribute names of the class in the migration, so when you execute a migration you know which translated attributes will be declared and not need to worry about attributes that are not declared when you create the migration.
Overwriti
@vortizhe
vortizhe / gist:3370006
Created August 16, 2012 13:10
Unicorn Fix - Update gemfile after deploy
before_exec do |server|
ENV["BUNDLE_GEMFILE"] = "/var/www/proyectname/current/Gemfile"
end
@kazpsp
kazpsp / passwords_controller.rb
Created August 14, 2012 16:40 — forked from guilleiguaran/passwords_controller.rb
StrongParameters with Devise
# app/controllers/users/password_controller.rb
class Users::PasswordsController < Devise::PasswordsController
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
private :resource_params
end
@vortizhe
vortizhe / gist:3341081
Created August 13, 2012 14:08
Extend RefineryCMS wysiwyg
rake refinery:override javascript=admin
admin.js
if (typeof(custom_wymeditor_boot_options) == "undefined") {
custom_wymeditor_boot_options = {
classesItems: [
{name: 'text-align', rules:[{name: 'left', title: '{Left}'}, {name: 'center', title: '{Center}'}, {name: 'right', title: '{Right}'}, {name: 'justify', title: '{Justify}'}], join: '-', title: '{Text_Align}'}
, {name: 'image-align', rules:[{name: 'left', title: '{Left}'}, {name: 'right', title: '{Right}'}], join: '-', title: '{Image_Align}'}
, {name: 'font-size', rules:[{name: 'small', title: '{Small}'}, {name: 'normal', title: '{Normal}'}, {name: 'large', title: '{Large}'}], join: '-', title: '{Font_Size}'}
@brenes
brenes / gist:3293652
Created August 8, 2012 09:07
jquery validation for selects and uniform
$('form').validate({
errorPlacement: function(error, element) {
if (element[0].tagName == "SELECT") {
element.parent().addClass('error');
}
return true;
},
unhighlight: function(element, errorClass, validClass) {
@qrush
qrush / proc.rb
Created April 27, 2012 20:59
Rails 3.2 Tagged Logger examples
# somewhere in your middleware stack...
# request.env['yourapp.someid'] = "1337"
YourApp::Application.configure do
config.log_tags = [
-> request {
request.env['yourapp.someid']
}
]
end
@tjh
tjh / character_set_and_collation.rb
Created January 31, 2012 16:07
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@rsierra
rsierra / rawclone_bundler.rb
Last active September 28, 2015 06:38
Script para generar el Gemfile de bundler a partir de un 'gem list'
#!/usr/bin/env ruby
# So you want to start developing an already "woking" project. No
# bundle, config.gem's not present or messing up dependencies. Fear
# not!
# Do a "gem list" wherever the project is already working
# (production?, some colleage machine?). Make a file with this format:
#
# chronic (0.2.3)
# colored (1.1)