Craig Hoffman


2,220 Experience
12 Lessons Completed
1 Question Solved


Posted in Esbuild

What it looks like is any sort of "image (jpg, SVG, maybe fonts, etc...)" reference in a CSS file, for example, background-image URL("someimage.jpg") is not being picked up / path issue.?. Hence why Bootstrap Icons are not working.

Posted in Esbuild

Thanks, Chris. Tried setting config.assets.css_compressor = :sass to nil and no luck. Even tried enabling the:sass option, recompiled the app. No luck. I noticed this is happening with another Yarn package I'm using that has images (SVG) in the node_modules dir. I'm wondering if something should be added to the file?

Posted in Esbuild

I'm trying to get away from Webpacker... Installed the gem JSBundling on a Rails 6.0.1.x app, followed the setup procedures to use EsBuild, and it worked. Got BootStrap 5 working with the guidance from your screencast. Thanks! Installed bootstrap icons with Yarn. Added: @import bootstrap-icons/font/bootstrap-icons to my application.bootstrap.scss file. Fired up the dev server - bin/dev - works perfectly. Icons!!! When I test in the production setting (rails s -e production), it's broken. I've tried RAILS_ENV=production rake assets:precompile`` without any success. It does work if I change this config setting in the Config -> Environment -> Production config.assets.compile = false ``` to true. Thoughts on how to remedy this?

Posted in Best Approach for Updating Attributes On Join Table

Thanks Chris for the response. Sorry for the delay, I had pivot to another project for small feature update. I feel I'm close to solving this issue, but I'm drawing a blank on the best approach to submit a form that can update multiple rows / (or ids). I'm using SimpleForm and the view/_form looks like this:

simple_form_for(@author_article, url: article_author_articles_path,  html: {class: 'form-group'}) do |f|
  - if @article.errors.any?
    = render partial: "partials/error_messages", locals: {object: @article}

  - @authors.each do |i|
      = f.label i.fullname
      = f.hidden_field :author_ids
      - i.author_articles.where("author_id = ?","article_id = ?", do |o|
        = f.input :author_sequence_ids, 
          collection: @author_sequences,
          selected: o.author_sequence_id, 
          label: false,
          prompt: "Choose Something"
    %p= f.submit 'Save', class: 'btn btn-sm btn-primary text-center'

The form appears like this in the view.

Chris Rock <select><option "Choose Something ... 
Jimmy Fallen <select><option First ... selected
Chuck Norris <select<option Second ... selected 
<button>Save ... 

And of course in the controller (AuthorArticlesController) I'm permitting author_sequence_ids: [], author_ids: [], article_id
The issue I'm having is the dropdown menu does not know the author. Any advice you or anyone else would be welcome!

Posted in Running Yarn offline

I have a production server Running Rails 6 (latest version) that is extremely locked down. I don't manage the infrastructure surrounding (firewalls, IPs, etc...) the server. Only a few things are allowed to connect and pass through. One of the challenges I'm facing is Yarn. Yarn seems to be tightly integrated into Rails 6, this is fine if the server can connect to the Yarn package repo but becomes a problem/nuisance when it can't. I've tried following this from Yarn without any success.

Whenever I run Yarn install --check-files, it returns 'can't connect ... ' or something like it, which is expected. If you need to precompile assets, open the console (rails c), and so on Yarn wants to run.

Any thoughts/guidance anyone can provide in managing Yarn on this machine would welcome.

Posted in Best Approach for Updating Attributes On Join Table

I have a view (show) that display's an Article. The Article has several Author[s]. The Article and Author models look like this:


Article Model
has_many author_articles
has_many articles,  through: :author_articles 

Author Model
has_many author_articles
has_many author,  through: :author_articles 

AuthorArticle Model
belongs_to article
belongs_to author

The join table (AuthorArticle) contains an article, author id columns, and another column called position_id. The Position model is also a has_many through. It looks like this:


Position Model
has_many author_articles
has_many positions,  through: :author_articles 

Author Model
has_many author_articles
has_many author,  through: :author_articles 

AuthorArticle Model
belongs_to article
belongs_to author
belongs_to position

Here's what I would like to do and I am not exactly sure how to implement it. I would like to click on the author's name from the article show view, open a modal (already done) and have a form (SimpleForm) where the user can select a position (first, second, third, etc...) and press submit. The order of the author is important. Yes, there can be several "first/lead" authors. The form post would update the join table (AuthorArticle) position_id column with the position selected. Authors are added when a new article is created or updated.

Does this make sense? Let me know if you need more context? Something doesn't feel right about this approach and I'm open to suggestions/feedback/ideas.


Posted in How do I configure Rails to use a Proxy URL

Let's say we have a Rails project operating on the domain The way the organization's infrastructure is set up, gets proxied into a new URL called - . When I start the server with Rails s -e production and navigate my browser to, all the CSS, assets, JS is broken. After some research I changed this config:
config.action_controller.asset_host = '' and the CSS, JS, and assets seem to be working again. Great. One thing that's certainly not right is the links / main navigation (routes). For example, when navigating to any page in the browser, for example,, I get a 404. Seems like there should be a "pass-through" when a request comes in it gets mapped it to Does this make sense? I could use some assistance. What's the best approach here?

My Setup
Rails 6.x.x
Ruby 2.7.x


I would like to get everyone's take on what are is the best practice for storing DB usernames/passwords, API keys, Contstants, Etc... Should they be stored in config/environments/ then in test, development production accordingly? Some of these files do end up in verstion control. Thoughts?

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.