Skip to content

Instantly share code, notes, and snippets.

Avatar
🖤

James Lafa jameslafa

🖤
View GitHub Profile
@jameslafa
jameslafa / Gemfile
Created Jun 13, 2013
A list of a few rails testing and debugging gems
View Gemfile
group :development do
gem 'quiet_assets' # Remove useless logs
# Debugging in the browser
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem 'guard-livereload'
gem 'seed_dump'
@jameslafa
jameslafa / application.rb
Created Jun 13, 2013
Use asset piple with SVG
View application.rb
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg)
@jameslafa
jameslafa / Gemfile
Created Jul 9, 2013
ActiveAdmin : Make model compliant with ActiveModel and StrongParameters Thanks to @daxter (twitter @seanlinsley) for his help : https://github.com/gregbell/active_admin/pull/2326
View Gemfile
# Rails 4.0 just went out and right now to make ActiveAdmin works, you need
# to add this in your Gemfile
gem 'devise', github: 'plataformatec/devise'
gem 'responders', github: 'plataformatec/responders'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'ransack', github: 'ernie/ransack', branch: 'rails-4'
gem 'activeadmin', github: 'gregbell/active_admin', branch: 'rails4'
gem 'formtastic', github: 'justinfrench/formtastic'
@jameslafa
jameslafa / bash.sh
Created Jul 10, 2013
Rebuild schema.rb from scratch using every migrations
View bash.sh
# Rebuild database from schema.rb
rake db:reset
# But this rebuild database from all migrations
rake db:drop db:create db:migrate db:seed
@jameslafa
jameslafa / admin-projects.rb
Created Jul 17, 2013
Paperclip with Rails4 and active admin
View admin-projects.rb
ActiveAdmin.register Project do
# Don't forget to add the image attribute (here thumbnails) to permitted_params
controller do
def permitted_params
params.permit project: [:title, :summary, :description, :thumbnail, :date, :url, :client_list, :technology_list, :type_list]
end
end
form do |f|
@jameslafa
jameslafa / admin-projects.rb
Created Jul 17, 2013
Add multiple images to a model using Paperclip and active_admin
View admin-projects.rb
ActiveAdmin.register Project do
controller do
def permitted_params
params.permit project: [:title, :summary, :description, :thumbnail, :date, :url, :client_list, :technology_list, :type_list, :images_attributes => [:picture, :id, :_destroy]]
# to add unlimited :image, you need to permit :images_attributes => [:picture, :id, :_destroy]
# - picture for the image
# - id to avoid duplicates
# - _destroy if you want to allow image delete
end
end
@jameslafa
jameslafa / global_macros.rb
Created Jul 26, 2013
Counting elements using capybara and rspec
View global_macros.rb
RSpec::Matchers.define :match_exactly do |expected_match_count, selector|
match do |context|
matching = context.all(selector)
@matched = matching.size
@matched == expected_match_count
end
failure_message_for_should do
"expected '#{selector}' to match exactly #{expected_match_count} elements, but matched #{@matched}"
end
@jameslafa
jameslafa / active_admin.rb
Created Jul 29, 2013 — forked from fred/active_admin.rb
Show pretty booleans in active_admin
View active_admin.rb
# It extends activeadmin to show pretty boolean values
#
# config/initializers/active_admin.rb
module ActiveAdmin
module Views
class TableFor
def bool_column(attribute)
column(attribute){ |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe }
end
@jameslafa
jameslafa / event.rb
Last active Jul 5, 2019 — forked from bbonamin/event.rb
Handle translations with Globalize3 in Active Admin with Rails 4
View event.rb
#app/models/event.rb
class Event < ActiveRecord::Base
translates :title, :description, :summary
has_many :event_translations
accepts_nested_attributes_for :event_translations, :allow_destroy => true
end
@jameslafa
jameslafa / spec_helper.rb
Last active Aug 29, 2015
Rspec + capybara configuration
View spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'capybara/poltergeist'
require 'database_cleaner'
# Requires supporting ruby files with custom matchers and macros, etc,