William Jones


6,630 Experience
5 Lessons Completed
8 Questions Solved


I have 2 URL's to access the same Rails application. One URL is internal to our network and does not require authentication. The other is accessible outside our network and does require authentication. I put the following code in the app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
before_action :authenticate_user!, if: :outside_the_network_is_true?


def outside_the_network_is_true?
logger.info 'request.original_url[7..9] = ' + request.original_url[7..9]
outside_the_network = false
if request.original_url[7..9] == 'ops'
outside_the_network = true


This forces the user to sign in when using the external URL but allows them access without signing in when using the internal URL. This all works as expected. However I have some JavaScript that periodically requests data from the API in the same application. If the request comes from the external URL page everything is fine, but if it comes from the internal URL page I get a 401 unauthorized error. I am assuming that Devise is doing something to check if the request is coming from a signed in user and rejecting it because the user is not signed in. But I could be wrong. How should I get around this?
Any help would be much appreciated.

Posted in Stimulus Reflex error

I am getting the an error when following the 'Introduction To Stimulus Reflex video'. What would cause this and what are possible solutions?

Uncaught Error: Cannot find module './application_controller'
at webpackMissingModule (index.js:1)

I had problems because I didn't follow the instructions exactly. Everything works now.

I have been following the instructions at https://gorails.com/setup/ubuntu/20.04#ruby-rbenv. I get the following error,

Installing nokogiri 1.10.9 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /var/lib/gems/2.7.0/gems/nokogiri-1.10.9/ext/nokogiri

/usr/bin/ruby2.7 -I /usr/lib/ruby/2.7.0 -r ./siteconf20200522-63887-8bdogk.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.

The rails version installed is, the ruby version is 2.7 and the Ubuntu version is 20.04 LTS. I am confused about the rails version because I used the 'gem install rails -v' command.

Any advice about how to proceed would be welcome.

Posted in Prawn disposition: "inline" not working

I deleted all the old pallet data, created some new data and that displayed inline without any problem.

Posted in Prawn disposition: "inline" not working

I have been following the Railscast video #153 PDFs with prawn. I want the PDF to display inline instead of down loading it, the following is my code;

def show
respond_to do |format|
format.pdf do
pdf = Prawn::Document.new
pdf.text "Origin: "[email protected]_cc
send_data pdf.render, filename: "Pallet #{@pallet.id}.pdf",
type: "application/pdf",
disposition: "inline"

I am using rails 5.1.7, ruby 2.5.3 and prawn 2.2.2.

However the file is not shown inline but is still down loaded. What could be the cause of this?

I continued with my google searches and found a suggestion that worked. I just ran 'gem update' and then 'rails new pallet_tracker' and everything worked.

I have created many rails projects to date without any problems. However when I tried to create a new project today using the command 'rails new pallet_tracker' I get the following error,

/home/billj/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:2302:in `raise_if_conflicts': Unable to activate concurrent-ruby-ext-1.1.5, because concurrent-ruby-1.1.6 conflicts with concurrent-ruby (= 1.1.5) (Gem::ConflictError)

I get the same error when I enter the 'rails -v' command.

I am not sure how to resolve the conflict. There is no project so I can't change the gem file. Perhaps I have an outdated version of something but I don't know what that is. Any pointers will be gratefully received.

I changed the sort in the view as follows and everything works.

<%= form.fields_for :prospect_calls, form.object.prospect_calls.sort_by(&:call_date) do |p| %>

Sorry for the confusing question, I couldn't think of a better way to phrase it.

I have a 'Prospect' model that accepts nested attributes for 'prospect_calls'. When editing the prospect I need to see all the prospect calls in the order that they were made and be able to add a new prospect call if required.

In the controller I have the following code,

@prospect.prospect_calls.build call_date: @required_date

This adds a new call record that can be edited or ignored by the user. In the prospect model I reject prospect calls if the "who" field on the call record is not entered. This all works perfectly if the calls are not sorted. If they are sorted the new call record does not appear in the call list on the edit view.

To sort the calls I have included the following in the view,

<%= form.fields_for :prospect_calls, form.object.prospect_calls.order(:call_date) do |p| %>

This sorts the calls perfectly, but the new call record does not appear in the list of calls.

How can I sort the call records and have a new call record on the edit view?

Posted in How do I style select options?


Posted in How do I style select options?

I have options for a select field from 2 sources (this years options and last years options). In the drop down list I would like to distinguish the options between the sources (e.g. this years options with a green background, last years with a pink background).

Posted in How do I drag and drop an image file?


Posted in How do I drag and drop an image file?

It turns out to be really easy. Just click and hold over the email attachment and drop it on the choose file button on the file field on the application and let go of the mouse button. That's it.

Posted in How do I drag and drop an image file?

I have a rails application that can upload an image using CarrierWave and MiniMagick and a file_field. This seems to be the usual way to do things and works well. I have a user that wants to open an email that has an image attachment and drag and drop that image into my application. This would be quicker than them downloading the email attachment and then attaching it in the application from the download folder. Is there an easy way to code this?

Posted in How should I deal with lots of images?

Thanks for your help.

Posted in How should I deal with lots of images?

Thanks Daniel. There is a bit of paranoia amongst management here about storing company data outside the network. We have plenty of storage on the company servers, I am just not sure how to access the images if they are not stored in the Rails app. Do you know of any way to do that?

Posted in How should I deal with lots of images?

I have a Rails app that lets users select an invoice from a list of invoices. When selected a view of the image of the invoice is displayed with an image of the customer signature overlayed on top. This is all working well with the test invoice and signature images I am using (9 of each). They are all kept in the app/assets/images folder. However the production data contains hundreds of thousands of invoice and signature images. What is best practise for storing these images so they are accessible by the Rails app?

Hello Chris,
I am only using Puma or Passenger, definitely not both at the same time. When using Puma I start the rails server (i.e rails s -e production) from the application directory and the pages of the app display correctly showing data from the database calls made by the app. After stoping Puma (CTRL C) I start apache with the command 'sudo service apache2 start'. This starts correctly and when I try to access the app I get the "TinyTds::Error (closed connection):" displayed in the rails production log file. The log messages are shown below,

I, [2019-02-04T17:11:14.815714 #2769] INFO -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] Started GET "/" for at 2019-02-04 17:11:14 -0500
I, [2019-02-04T17:11:14.904719 #2769] INFO -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] Processing by TurkeytoteController#totals as HTML
I, [2019-02-04T17:11:14.942821 #2769] INFO -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] Completed 500 Internal Server Error in 38ms
F, [2019-02-04T17:11:14.943925 #2769] FATAL -- : [6933cfd7-efa5-492c-a538-87f5e04e9723]

F, [2019-02-04T17:11:14.943996 #2769] FATAL -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] TinyTds::Error (closed connection):
F, [2019-02-04T17:11:14.944074 #2769] FATAL -- : [6933cfd7-efa5-492c-a538-87f5e04e9723]

F, [2019-02-04T17:11:14.944163 #2769] FATAL -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] app/controllers/turkeytote_controller.rb:95:in get_totals'
[6933cfd7-efa5-492c-a538-87f5e04e9723] app/controllers/turkeytote_controller.rb:76:in

I am not sure how to produce a full stacktrace, any advice would be welcome.

Thanks for all your help.



Hello Chris,
Thanks for the prompt response.
There is no problem connecting to the database when using just Puma. I can create, read, update and delete with no issues. When I use apache/passenger to access the application then I get the error.
When you mention 'ENV variables' can you be a little more specific? Perhaps there is something that I have not set correctly and I am ignorant of.



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.