RJ McCollam


3,930 Experience
2 Lessons Completed
4 Questions Solved


Posted in ElasticSearch connection refused

In my instance the issue was with localhost not being represented in my hosts file.

I adeed the following to it and was able to get past this.       localhost broadcasthost
::1             localhost
fe80::1%lo0     localhost

Posted in Search Filters/Report Generator

Thanks Joe and Chris for both of your feedback. I decided to go with ElasticSearch and Searchkick since there seems to be more current documentation for what I am trying to accomplish.

Posted in ElasticSearch connection refused

Mason, I know this was over a year ago you posted about it, but just curious if you ever fixed this. Or more importantly if you remember how you fixed it.

Running into the same issue on my end.

Posted in Search Filters/Report Generator

I am working on a project for a client that consists of a primary jobs model that has a number of forms (other models) within it.

I am needing to build out search functionality that searches through all models in order to return a job that matches. This search also needs to include filters with the ability to filter by client, time frame, and a couple other pieces of data.

In looking through possible solutions i think that the most recent video Chris did on elasticsearch with filters (https://gorails.com/episodes/search-filters-with-elasticsearch-aggregations) might be what I am after.

What I havent seen in the research I have done so far is searching through multiple models. Would elasticsearch with filters be a good option to accomplish what I am trying to?

Posted in Nested Model of an already nested model

I want to make sure my thinking is right more than anything else on this post. Hopefully I can explain myself clearly and get pointed in a good direction.

My Scenario

I have 3 models. Model A, Model B, and Model C.

Model A is the top level model and has Model B nested underneath it through a belongs_to/has_many setup.

I am needing to add a nested model (Model C) to Model B. Model C has not dependcy on Model A. Only Model B.

In building out Model C can I just go about it as I normally would using a belongs_to/has_many setup?

I imagine that going another level deep with nesting is possible, but I also imagine there are some special things to look out for in my routing and form setup.

My question in all of this being can I do it and what should I watch out for in doing so?

Posted in Form errors not displaying

Ah, thank you Chris. Updated that and I am all set. Really appreciate you answering.

Posted in Form errors not displaying

In my model for users I am validating the presence of a number of attributes using:
validates_presence_of :parent_1_first_name, :parent_1_last_name...

The beginning of my form object looks like this:
<%= form_for @user, url: {action: 'update'} do |f| %>

            <% if @user.errors.any? %>

                <div class="form-errors">

                    <h2><%= pluralize(@user.errors.count, "error") %> stopped you from updating this user:</h2>
                    <% @user.errors.full_messages.each do |msg| %>
                      <h4><%= msg %></h4>
                    <% end %>


            <% end %>

My Update method in my User controller looks like this:
def update
        subaction = params[:subaction]
        if @user.update(edit_user_params)
       flash[:success] = "#{@user.first_name} #{@user.last_name} has been updated."
       redirect_to edit_user_path(@user, anchor: subaction)
      flash[:error] = "Something went wrong and #{@user.first_name} #{@user.last_name} could not be updated. Please ensure all required fields have been filled out."
        redirect_to edit_user_path(@user)

When a user is updated, but is missing one of the fields I am checking form error messages do not display and instead I get a redirect to the edit path with my error message instead.

In googling around I don't see what I have setup incorrectly.

Posted in Implementing global app settings

Thanks Andrew. Wanted to make sure my head was in the right place and I wan't missing something obvious.

Posted in Implementing global app settings

I am wondering what the best way to go about setting up Settings for an application. Settings will consist of name, address, phone number, and some other project specific entries. What has me a little confused is that while many users will be accessing the app, these settings are to be specific to the app and not the user.

I will be letting admins edit these settings and my thought was to setup a model for Settings to store the values in the DB. However there wont be multiple Settings entires in the DB I just need one.

Is a model the right way to go in this instance and maybe I just manually create one entry for Settings that can be edited by anyone with the correct role?

Seems like a simple concept to me, but getting a little mixed up by it.

I have a user model in my application that has instances of 3 other models and what I am trying to do is to export to CSV all of the user information as well as the information for the other models related to that user.

In following the Export to CSV video on GoRails I am able to export all of the user's data through CSV, but am not sure how to also include records from these other models.

Since each user will have different totals of these other models I understand I probably cannot put all the data of a user on one line and would have to break it down like:

User Data
Parent Data for Above User
Medication Data for Above User

I'm not sure how to loop through these other models related to the user and output there data in my to_csv function.

Here is the code I am using to generate the CSV currently:

CSV.generate(headers: true) do |csv|
  csv << attributes
      all.each do |user|
          csv << user.attributes.values_at(*attributes)

Is this even possible considering that the headers would be different? Should I just make them separate exports?

Edit - Maybe a better question is if I break these out into separate CSV's I would only have the user_id in order to allow any association between users and the data in other CSV's.

How would I go about pulling in a value from the User model using the user_id in a CSV export for another model? For example in my parents export I wont to include the user's student_id.

I had the config.resource_keys uncommented for some reason and once I commented it out all worked as expected.

Thanks for your help here Chris.

Yes I did restart rails a few times to make sure it wasn't something silly like that.

The full trace can be found here - http://www.awesomescreenshot.com/image/2486026/389892e4c6723ca10f0a40718c89bdba

I have followed the instructions on this page https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-with-something-other-than-their-email-address to allow signing in with something other than the email, but when I try to login I get an error of unidentified method for the new key I am using. In this case student_id. I am able to create an account with the student id and email just fine.

In application_controller.rb I have added the parameters for both sign up and sign in.

  before_action :configure_permitted_parameters, if: :devise_controller?


    def configure_permitted_parameters
        devise_parameter_sanitizer.permit(:sign_up, keys: [:student_id, :email, :password, :password_confirmation])
        devise_parameter_sanitizer.permit(:sign_in, keys: [:student_id, :password])

In the devise initializer I have added the link config.authentication_keys = [:student_id]

Not sure what else I am missing, and don't know enough to read into the error all that well.

Posted in Ruby version stuck on macOS

I got this figured out. It looks like there was a rouge line in my .bash_profile that was putting rbenv in my $PATH and was casuing issues.

Cleared that up and was able to get things up and running.

Posted in Ruby version stuck on macOS

Haven't figured it out just yet.

In looking at .ruby-version and Gemfile they both have the correct version of Ruby I am wanting to use. Seems bizarre to me.

Posted in Ruby version stuck on macOS

Setting up my new MacBook Pro and am running into an issue with ruby versions.

At this point I have installed and am usin rbenv. I installed ruby 2.3.1 and when I ruby -v that is what it shows.

When I try to start the server on an app that specifies ruby 2.3.1 in the gemfile and in .ruby-version I get this message - "Your Ruby version is 2.0.0, but your Gemfile specified 2.3.1".

Not sure where this rouge setting of 2.0.0 is at.

Posted in File Uploads with Refile Discussion

I thought that this was happening to me too, but when I actually thought about it I saw it was working. Even if you upload to a 3rd party host the rack app for refile will download that image, process it, and still give it a local URL. The true test to see if it is uploading to S3 is to look in your bucket to see if the images are being stored there. Turns out mine was working all along.

Posted in File Uploads with Refile Discussion

I am having the same problem as your initial one. Did you figure it out and is that why you posted a link to your repo? Could you elaborate on what you did to correct it?

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.