Skip to content

Instantly share code, notes, and snippets.

View alexdesi's full-sized avatar

Alessandro De Simone alexdesi

View GitHub Profile
@alexdesi
alexdesi / gist:c35ca8da0d264b6a917ac62efa0aa969
Created December 12, 2023 08:30
Debugging Ruby on Rails error: ActionView::Template::Error (Webpacker can't find media/images/...
Sometimes, this error occurs when I run a rails app on my local:
```
ActionView::Template::Error (Webpacker can't find media/images/...
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
@alexdesi
alexdesi / mini_state_machine.rb
Created October 8, 2019 09:13
Mini state machine
# THIS IS WIP, NOT FULLY WORKING
class MiniStateMachine
# [initial_statuses, event, next_status]
@transitions = [
[[:s1, :s2], :event1, :s3],
[[:s3], :event2, :s4],
[[:s1, :s2], :event3, :s5]
]
@alexdesi
alexdesi / hash2csv
Created July 6, 2017 11:35
Script to convert an array of hashes to a CSV having the name of the columns name equals to the keys of the hashes
require 'date'
require 'csv'
def array_hash_to_csv(data, filename = "data.csv")
CSV.open(filename, "wb") do |csv|
csv << data.first.keys
data.each do |hash|
csv << hash.values
end
end
@alexdesi
alexdesi / ignore_cassettes
Created August 26, 2016 16:24
VCR - How to ingnore cassette in tests
VCR.turned_off(:ignore_cassettes => true) do
VCR.use_cassette('cassette') do
...
end
end
@alexdesi
alexdesi / list_asset_files.rb
Created April 10, 2016 17:27
List all the files included in the Rails assets
# Found in http://stackoverflow.com/questions/10994396/sprockets-rails-find-all-files-sprockets-knows-how-to-compile
Rails.application.assets.each_file { |pathname| puts pathname}
@alexdesi
alexdesi / gist:3793141
Created September 27, 2012 09:37
Create a user with authlogic without automatic login
user.attributes = { ... }
user.save_without_session_maintenance
@alexdesi
alexdesi / gist:3656399
Created September 6, 2012 13:45
Simple way to rename a key in a Hask
h = {:a => 1, :b => 2 }
h[:c] = row.delete(:a).last
>> put h
>> {:c => 1, :b => 2 }
@alexdesi
alexdesi / gist:3452770
Created August 24, 2012 16:46
How to use Factory Girl from the console in Rails 3
require 'factory_girl'
FactoryGirl.find_definitions
u = Factory.create(:user)
@alexdesi
alexdesi / run_one_migration
Created March 8, 2012 12:26
How to run only one migration
./script/runner 'require("./db/migrate/migration_name.rb").first.constantize.up'