RJ McCollam

Joined

2,690 Experience
0 Lessons Completed
3 Questions Solved

Activity

Posted in Format of created_at for date range using Searchkick

What I had before that was causing it to be put in an array was

<%= date_field :start_date, nil, value: params[:start_date] %>

and what I changed it to get just a normal string was

<%= date_field nil, :start_date, value: params[:start_date] %>

Posted in Format of created_at for date range using Searchkick

This whole thread goes to show my greeness in rails. The way that I was setting things up in my controller was fine. The issue was the way I had my date_field setup in my view. It was giving me the value in an array which was the cause of the error. Corrected my field setup to return just plain text and all is well with the world.

In all seriousness Chris you need to put a tip button on this site cause the attention you gave, especially considering the holiday, is more than appreciated. Yes I pay monthly for access, but this got me over a hump to meat a deadline. Thank you.

Posted in Format of created_at for date range using Searchkick

I think the issue might be in the format that the params are being sent through as.

If I set up simple variables for params like

client = params[:client]
start_date = params[:start_date]
end_date = params[:end_date]

then the output I get is

>>  client
=> "2"
>>  start_date
=> ["2018-11-01"]
>>  end_date
=> ["2018-11-30"]

So the dates are being wrapped as an array for some reason. Which is proably why that extra ] is what you were thinking could be the problem. Guess I need to fix that before I can go any further.

Posted in Format of created_at for date range using Searchkick

When I get the error and output the args I get what I think I am suppose to be getting {:client=>"2", :created_at=>{:gte=>["2018-11-01"], :lte=>["2018-11-30"]}}

Posted in Format of created_at for date range using Searchkick

In this particular instance to just test if it is working I am always making sure that those fields have values in them.

Posted in Format of created_at for date range using Searchkick

Not sure if the last comment came through or not. Not seeing it on my end, but post count for this thread went up.

Posted in Format of created_at for date range using Searchkick

My controller looks like this when pulling from the form

def index
        @page_title = "Search"

        query = params[:q] ? params[:q] : "*"
        args = {}
        args[:client] = params[:client] if params[:client].present?
        args[:created_at] = {}
        args[:created_at][:gte] = params[:start_date]
        args[:created_at][:lte] = params[:end_date]
        @results = Searchkick.search(query, where: args, order: {created_at: :desc}, aggs: { client: {} }, operator: "or")
    end

The error is:

[400] {"error":{"root_cause":[{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"flange_inspection_reports_development_20181121094552549","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"flow_iron_inspection_parts_development_20181121094558099","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"flow_iron_inspections_development_20181121094557605","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"inspection_reports_development_20181121094558340","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"iron_recertification_parts_development_20181121094558787","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"iron_recertifications_development_20181121094558607","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"job_work_orders_development_20181121094559344","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"jobs_development_20181121094558982","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"liquid_penetrant_reports_development_20181121094559535","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_inspection_report_magnetics_development_20181121094600104","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_inspection_reports_development_20181121094559769","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_inventory_parts_development_20181121094600334","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_inventory_sheets_development_20181121094600520","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_pressure_test_reports_development_20181121094600698","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"magnetic_particle_parts_development_20181121094600885","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"magnetic_particle_reports_development_20181121094601062","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}}]},"status":400}

Posted in Format of created_at for date range using Searchkick

When I have my controller setup to grab the form values it looks like this

def index
        @page_title = "Search"

        query = params[:q] ? params[:q] : "*"
        args = {}
        args[:client] = params[:client] if params[:client].present?
        args[:created_at] = {}
        args[:created_at][:gte] = params[:start_date]
        args[:created_at][:lte] = params[:end_date]
        @results = Searchkick.search(query, where: args, order: {created_at: :desc}, aggs: { client: {} }, operator: "or")
    end

The error I get is

[400] {"error":{"root_cause":[{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"flange_inspection_reports_development_20181121094552549","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"flow_iron_inspection_parts_development_20181121094558099","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"flow_iron_inspections_development_20181121094557605","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"inspection_reports_development_20181121094558340","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"iron_recertification_parts_development_20181121094558787","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"iron_recertifications_development_20181121094558607","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"job_work_orders_development_20181121094559344","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"jobs_development_20181121094558982","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"liquid_penetrant_reports_development_20181121094559535","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_inspection_report_magnetics_development_20181121094600104","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_inspection_reports_development_20181121094559769","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_inventory_parts_development_20181121094600334","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_inventory_sheets_development_20181121094600520","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"lubricator_pressure_test_reports_development_20181121094600698","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"magnetic_particle_parts_development_20181121094600885","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}},{"shard":0,"index":"magnetic_particle_reports_development_20181121094601062","node":"qCRs5n2SQ5CAedg5TImFyA","reason":{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]","caused_by":{"type":"illegal_argument_exception","reason":"Parse failure at index [0] of []]"}}}]},"status":400}

Posted in Format of created_at for date range using Searchkick

I am using searchkick to build out a searchform that has a couple different parts to it and searches across multiple models. I am specifically trying to get a date range setup so the user can search for results within a start and end date.

Here is how I am building my search query in my controller:

def index
        @page_title = "Search"

        query = params[:q] ? params[:q] : "*"
        args = {}
        args[:client] = params[:client] if params[:client].present?
        args[:created_at] = {}
        args[:created_at][:gte] = "2018-10-01"
        args[:created_at][:lte] = "2018-11-30"
        @results = Searchkick.search(query, where: args, order: {created_at: :desc}, aggs: { client: {} }, operator: "or")
    end

In passing in a hard coded value for a start and end date it does exactly what I want it to do.

When I attempt to pass these values in from the form in the same format I get a parse error.

I did go through and set the search_data up for each model in order to convert created_at to a time using created_at: created_at.to_time, but in indexing that data I ran into issues where my other search functions weren't working since my models don't all share the same data.

Am I missing the boat with my current implementation completely, or is there some formatting I can do in order to get this date range working?

I know I am reaching a little bit with my questions, but if all models DID have the same attributes, would I be able to setup aggregations just like in the video?

Is it possible to still use Aggregations when searching multiple models? Especially if each model doesn't have that particular value?

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.

127.0.0.1       localhost
255.255.255.255 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 %>

                </div>

            <% 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)
    else
      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)
    end
    end

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.

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

© 2020 GoRails, LLC. All rights reserved.