Skip to content

Instantly share code, notes, and snippets.

View jameslafa's full-sized avatar
🖤

James Lafa jameslafa

🖤
  • Personio
  • Berlin, Germany
View GitHub Profile
@jameslafa
jameslafa / Gemfile
Created June 13, 2013 07:11
A list of a few rails testing and debugging gems
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 June 13, 2013 07:14
Use asset piple with SVG
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg)
@jameslafa
jameslafa / Gemfile
Created July 9, 2013 20:18
ActiveAdmin : Make model compliant with ActiveModel and StrongParameters Thanks to @daxter (twitter @seanlinsley) for his help : https://github.com/gregbell/active_admin/pull/2326
# 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 July 10, 2013 19:21
Rebuild schema.rb from scratch using every migrations
# 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 July 17, 2013 10:28
Paperclip with Rails4 and active admin
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 July 17, 2013 15:11
Add multiple images to a model using Paperclip and active_admin
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 July 26, 2013 08:37
Counting elements using capybara and rspec
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 July 29, 2013 13:59 — forked from fred/active_admin.rb
Show pretty booleans in active_admin
# 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 July 5, 2019 23:32 — forked from bbonamin/event.rb
Handle translations with Globalize3 in Active Admin with Rails 4
#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 August 29, 2015 13:59
Rspec + capybara configuration
# 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,