This was a problem that plagued me for over an hour, and none of the answers I found on Google helped. I have a Rails 6 application with a model that has one ActiveStorage attachment. I needed a scope for all models that do not have a file attached. This is the model class:

ActiveRecord conveniently includes a scope called with_attached_file , which returns, intuitively enough, an ActiveRecord relation with all the models that have a file attached. Unfortunately, there is no corresponding without_attached_file scope.

Although there were several answers on StackOverflow that purported to solve this problem, none…

We had a little bit of a challenge at InView today: how to use nested attributes in forms without necessarily creating a new record in the database for every form submission. The solution turned out to be quite simple.

At InView, we have two (relevant) models: Report and Category. A Report has_and_belongs_to_many Categories. Each Category has one attribute: name. Category names should be unique (although this isn’t enforced through ActiveRecord for reasons I won’t go into here). For this reason, when a report is submitted with nested attributes for its categories, the categories should not be created anew if there…

Today I ran into an interesting problem. I needed to scope a Rails model by checking whether it had a child with a certain attribute. The solution was simple but a little hard to find online, so I thought I’d share.

I started out with two models: Applicant and Application. Every applicant has_one application, and every application has a status. I want to create an :active scope for the Applicant class, in order to list only applicants whose application status is "in review". Here are the models.

Creating the Scope

It turned out creating the scope was simple. All I had…

In the course of our lives as programmers, at some point we eventually will have to make an issue report against an open source project. Whether your issue report is a question, a bug report, or a feature request, filing a bug report is a deceptively complicated technical and interpersonal task. You’ll need to be prepared to spend a significant amount of time on your report; you’ll find that the decision of whether to file a report often comes down to the question of whether it’s faster to write an issue report or solve your problem another way. …

I’ve been working on InView’s informational site and have run into a special use case. It’s a mostly static site with two contact forms and we’re using the mail_form gem to handle e-mails from the forms. For the most part, the default mail_form contact form works for the e-mails that get sent to us. However, we also wanted to send an e-mail to each person who submits the form inquiring about how to get involved with the project, letting them know we got their e-mail and explaining next steps. …

This is a short post about how I fixed a Jest error with my React app. This error affected two things:

  • Jest test runs failed with the error TypeError: environment.setup is not a function.
  • Travis CI passed despite the failure, probably due to npm test exiting with 0.

Initial Configuration

This was our package.json file:

This was our src/App.test.js file:

And this was our .travis.yml file:

The Solution

The solution turned out to be really simple. First, I deleted "jest":"^22.4.4", and "jest-cli":"^22.4.4", from the package.json file. Next, I ran rm -rf node_modules from within the project directory before running npm install

Earlier I ran into a problem that gave me a bit of trouble. I was testing a single-page, mostly static, app built with Rails 5.2 and tested using RSpec 3.7. Specifically, I needed to test that the controller set flash messages correctly; this proved difficult because, under Rails 5 testing practices, the RSpec describe block does not name a controller class. In this post I want to explain how this problem presented and what I did to solve it.

Context

Controller testing has changed significantly in Rails 5, and by “changed significantly”, I kind of really mean “removed entirely”. The issue…

This is something I wrote about how Java handles passing parameters for an introductory programming class. Since I already knew the basics, I took the opportunity to take a deep dive into the pass-by-reference and pass-by-value methods of param passing. I hope others will find this as edifying as I did.

Parameters are a part of the interface of a subroutine that enable data to be passed into the subroutine when it is called (Eck, 2016). This enables the subroutine to dynamically incorporate the appropriate data into its operation. Take the following program for example:

public class AddNumbers { public…

There has been much buzz about the --api mode in Rails 5, which creates a REST API without views. Rails 5 makes it very easy to create JSON APIs, with ActiveModel::Serializer handily creating custom JSON objects from model attributes. But what if you’re writing a functional app that doesn’t need models?

In this tutorial, I am going to walk through creating a calculator API that takes a request body with a dossier and computes the person’s age from their birthdate. …

Dana Scheider

Technical lead at InView Dating (https://inview.info)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store