• This repository has been archived on 18/Sep/2020
  • Stars
    star
    264
  • Rank 155,103 (Top 4 %)
  • Language
    Ruby
  • Created about 11 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sprockets Better Errors Build Status

What

Errors, more of them, and better. For sprockets, specifically sprockets-rails < 2.1. The goal of this library is to make it painfully obvious when you've done something wrong with the rails asset pipeline. Like what?

Let's say you're referencing an asset in your view

<%= stylesheet_link_tag "search" %>

This works in development but you'll find if you're precompiling your assets that it won't work in production. Why? By default sprockets is configured only to precompile application.css. Wouldn't it have been great if you could have been warned in development before you pushed to production and your site broke?

Asset filtered out and will not be served: add `config.assets.precompile += %w( search.css )` to `config/application.rb` and restart your server

That would be AMAZING! Well this gem adds these types of helpful errors!

Compatibility

Rails > 3.2.0 and < 4.0.6. See gemspec for details.

If you're using Rails 3.2 you will need to enable the Rails 4 asset pipeline in Rails 3.

Install

In your Gemfile add:

gem 'sprockets_better_errors'

Then run:

$ bundle install

And add this line to your config/environments/development.rb:

config.assets.raise_production_errors = true

Now develop with some sprockets super powers!

The Errors

We try to catch all mistakes but we're not perfect. Here's a list of the things we watch out for

Raise On Dev asset not in Precompile List

This is one of the most common asset errors I see at Heroku. We covered this error in the "Why" section above. Incase you're skipping around here's the run down:

Let's say you're referencing an asset in your view

<%= stylesheet_link_tag "search.css" %>

This works in development but you'll find if you're precompiling your assets that it won't work in production. Why? By default sprockets is configured only to precompile application.css. Wouldn't it have been great if you could have been warned in development before you pushed to production and your site broke?

Asset filtered out and will not be served: add `config.assets.precompile += %w( search.css )` to `config/application.rb` and restart your server

Add this gem and you get that error.

Raise When Dependencies Improperly Used

This one may be a bit of an edge case for most people, but the difficulty in debugging (hours, days, weeks) is well worth the check.

If a dependency is used in an ERB asset that references another asset, it will not be updated when the reference asset is updated. The fix is to use //= depend_on or its cousin //= depend_on_asset however this is easy to forget. See rails/sprockets-rails#95 for more information.

Currently Rails/Sprockets hides this problem, and only surfaces it when the app is deployed with precompilation to production multiple times. We know that you will have this problem if you are referencing assets from within other assets and not declaring them as dependencies. This PR checks if you've declared a given file as a dependency before including it via asset_path. If not a helpful error is raised:

Asset depends on 'bootstrap.js' to generate properly but has not declared the dependency
Please add: `//= depend_on_asset "bootstrap.js"` to '/Users/schneems/Documents/projects/codetriage/app/assets/javascripts/application.js.erb'

Implementation is quite simple and limited to helper.rb, additional code is all around tests.

Upstream

Why not add this code upstream? I already tried, there are several PR awaiting merge. If you found this Gem useful maybe give them a :+1:.

Tests

Here's a one liner to running tests

$ export RAILS_VERSION=4.0.0; bundle update; bundle exec rake test

License

MIT

More Repositories

1

Octave

my octave exercises for 2011 stanford machine learning class, posted after the due date of course
MATLAB
818
star
2

sextant

find your route on a long journey over Rails with Sextant
Ruby
569
star
3

likeable

Use Redis to make your Ruby objects Likeable
Ruby
330
star
4

puma_auto_tune

Puma performance without all the (T)pain
Ruby
227
star
5

reddit_on_rails

A Hero's Journey
195
star
6

explain_shell

Ruby
113
star
7

let_it_go

Make sure your string literals are Frozen
Ruby
88
star
8

method_cacheable

Cache method calls and speed up your Ruby on Rails application with MethodCacheable.
Ruby
79
star
9

rrrretry

did I stutter?
Ruby
72
star
10

going_the_distance

Distance Measurements are Awesome!
Ruby
61
star
11

attendance

Speed up ActiveRecord#present? calls with the power of monkeypatching!
Ruby
60
star
12

q

A universal interface for Ruby queueing backends.
Ruby
39
star
13

ruby_view_server

Ruby
34
star
14

ruby_javascript_data_viz

Ruby
29
star
15

wicked_example

an example for the wicked gem
Ruby
29
star
16

hey_you

Use postgres to trigger custom events
Ruby
23
star
17

threaded_in_memory_queue

A non-durable in memory threaded worker queue for Ruby
Ruby
22
star
18

keytar

Make your keys awesome again with this simple library
Ruby
21
star
19

routes_controller_exercise

Ruby
19
star
20

simulate_ruby_web_memory_use

Simulates a web server running multiple threads and the amount of memory it needs
Ruby
17
star
21

tiny_queue

a tiny example of a threadsafe queue in C
C
16
star
22

schneems

The blog of schneems. Written by schneems, it is a blog. An internet web log.
HTML
16
star
23

living_dead

ITS ALIVE!!!!!!! (or is it?)
Ruby
15
star
24

arrays_and_active_record

Exercise for Week 7 of Class.
Ruby
14
star
25

WhySpam

Take a big bite out of Spam with Ruby On Rails
JavaScript
13
star
26

move_logic_to_controllers

Ruby
12
star
27

threaded

Lighter than actors, simpler then threads. Get threaded!
Ruby
10
star
28

resque_def

Love Resque? Hate Boilerplate? Use resque_def!
Ruby
9
star
29

united-dictionary

A multi-lingual user submitted dictionary
Ruby
8
star
30

Potential-Friend-Finder

Ruby
7
star
31

likeable_example

this is an example app for the likeable gem
Ruby
6
star
32

rate_throttle_clients

Ruby
6
star
33

Gowalla-Style-Photo-Browser

Page through your photos with ease using jquery
JavaScript
5
star
34

heroku-bouncer-demo

Ruby
5
star
35

heroku_ulimit_to_ram

Ughhhh, don't use this
Shell
4
star
36

active-storage-attachment-example

Ruby
4
star
37

non-developers-on-rails

Ruby
4
star
38

Selenium-RC-Beta-2

Selenium RC Beta 2
4
star
39

git_test

test your code, store it in git, share with teammates
Ruby
4
star
40

dotfiles

Vim Script
4
star
41

Roulette

Pre-Sharding so simple, you'll shoot yourself : p
Ruby
4
star
42

proc_to_lambda

Convert your Procs to Lambdas
Ruby
3
star
43

minimumviablerubywebserver

it's a web server, it's ruby, it's minimum viable and Heroku compatible, check it out
Ruby
3
star
44

minimal-ruby

Ruby
2
star
45

require_array_source_memory_problem

Ruby
2
star
46

repl_runner

Runs REPL like things, cause you know. REPL
Ruby
2
star
47

which_problem

Rust
2
star
48

heap_problem

Demonstrates that a non-retained object is sometimes still present in the heap
Ruby
2
star
49

ruby-26-bundler-issue

Ruby
2
star
50

MagicArg

Make our arguments magical
Ruby
2
star
51

rspec_test_project

Ruby
1
star
52

mama_schneems

Ruby
1
star
53

memory_notes_and_whatnot

Ruby
1
star
54

dotenv-buildpack

A cloud native buildpack (CNB) for injecting contents of your .env into your app at build time for local development
Rust
1
star
55

cant_stop

Programs used to demonstrate a solution of "optimal stoping"
Ruby
1
star
56

rails_monkeypatch_require_issue

Ruby
1
star
57

postgresql

Ruby
1
star
58

UpDown

Markdown editor
JavaScript
1
star
59

implement_ruby_hash_syntax_with_parslet_example

Ruby
1
star
60

codetriage-ko1-test-app

Ruby
1
star
61

advent_2021

Rust
1
star
62

basic_rust_lol_cnb_buildpack

Rust
1
star
63

kraken

🐙 Kraken MMO Distributed Framework :octocat:
Ruby
1
star
64

type_script_yargs_playground

TypeScript
1
star
65

max_manhattan_distance

An algorithm of my own design
C
1
star
66

heroku-buildpack-force-compile

Shell
1
star
67

omgcnb

Ruby
1
star
68

MailFactory

a tool for generating a mail object that you can use to test your apps email parsing behavior.
Ruby
1
star
69

rails-6-simple-2023-06-06

Ruby
1
star
70

rails51_webpacker

Ruby
1
star
71

buildit-gems

builds gems
Shell
1
star
72

Wordpress-For-Deployment

Wordpress Install for Capistrano Deploy
PHP
1
star
73

bullet_stream

Rust
1
star
74

kodyok

Best Free Wordpress Theme
JavaScript
1
star
75

DelayedLog

1
star