Chris Oliver

Joined

291,480 Experience
86 Lessons Completed
296 Questions Solved

Activity

Yeah, spam check. Code looks suspicious. :) I'll unmark them as spam.

Nope, minor version changes are only bug and security fixes. That error comes from Capistrano, not Ruby.

Posted in Inviting Users with devise_invitable Discussion

Generally for that, you'd want a public or private boolean on the Project.

Then you'd change your query for finding the project. A high level example:

def set_project
  @project = Project.find(params[:id])

    # Private projects require use to verify the user has access.
    if @project.private?
      raise ActiveRecord::NotFoundError unless @project.users.include?(current_user)
    end
end

Ideally, you'd use something like Pundit to do the authorization. That way it can be applied always and not be forgotten somewhere.

Hey Sam,

I'm assuming you've already went and re-run cap install to regenerate your configs.

Can you post more of the stacktrace? Just seeing the error alone isn't that helpful. It's more useful to see where in the code the error happened so you can look it up in the Capistrano repo and see what it wants so you can figure out what you did wrong.

I'll be curious to see where it happened. It might just be a typo in the config or something changed in a newer Capistrano.

Posted in Deploy Ubuntu 18.04 Bionic Beaver Discussion

Also, don't worry about secrets.yml. You'll need to symlink master.key on your server though so it can decrypt credentials. You'll go into the shared folder, and create the master.key file and then add it to the list of files to symlink every deploy. That should be all you need for that since the credentials.yml.enc is already stored in your git repo.

Posted in Deploy Ubuntu 18.04 Bionic Beaver Discussion

Hey Glory!

Sounds like your server can't authenticate with your git repo. There are two options for this.

  1. You can add SSH keys on your server. Take the public key from the server and add it as a deploy key on your git repo.
  2. Let Capistrano forward your development machine's ssh key to the server and use it to clone your git repo.

I usually use #2.

They outline a bunch of details of this here in the Capistrano docs: https://capistranorb.com/documentation/getting-started/authentication-and-authorisation/

Posted in How to monitor account progress?

This would be a good little episode. I'll add it to my list.

Basically when a user takes an action, you just want to store that on their account so you can check and see if it's done and then you can display the progress bar.

At a high level, you'd have to:

  1. Create a new database for every account in your system. Accounts probably live in the primary database, but then you'll have separate databases for their data.
  2. Migrate the data
  3. Have a before_action on ApplicationController that switches the ActiveRecord::Base connection based upon the account.

ActiveRecord::Base.establish_connection({:adapter => "postgresql", :database => current_account.db_name, :host => "wherever", :username => "username", :password => "password" })

Rails 6 is adding some support for multiple databases, but I'm not sure if it'll be useful for what you're trying to accomplish.

Also keep in mind (via https://stackoverflow.com/a/1157008/277994)

A PostgreSQL "schema" is roughly the same as a MySQL "database". Having many databases on a PostgreSQL installation can get problematic; having many schemas will work with no trouble. So you definitely want to go with one database and multiple schemas within that database.

Apartment uses schemas like this by default, so you may just want to use that.

Posted in i'd like to replace ransack with elasticsearch.

All my elasticsearch episodes are using the Searchkick gem which has been great for me.

You'll also need the ElasticSearch server running locally for development and then with the Heroku addon in production.

Posted in Format of created_at for date range using Searchkick

Those plain fields that aren't using form like form.date_filed always trip me up too. Small argument differences can mess up your params really easily. Thanks for sharing! :D

Posted in Format of created_at for date range using Searchkick

Ah ha! That was a weird one to track down! Glad you got it fixed.

What did you do to fix your date field? I imagine someone might find your solution helpful as well in case they stumble upon this.

A tip button is a fun idea. Paypal's got something kinda like that: https://www.paypal.me/gorails

Posted in Format of created_at for date range using Searchkick

Also I found this when searching the error:

https://stackoverflow.com/questions/48749364/how-to-fix-the-error-failed-to-parse-date-field-in-elasticsearch

Which points out to me that you may be passing in data wrong. It appears to put the value it cannot parse inside the [] here...and that makes it seem like your value is just a ].

failed to parse date field []]

Have you double checked to make sure that args is printing out everything correctly? I still feel like that's the source of your problem.

Posted in Format of created_at for date range using Searchkick

Okay yeah. :)

I wonder if you need to specify range before the attribute like it shows in the docs. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

What happens if you add debug: true to your query?

Product.search("soap", debug: true)

Posted in ActiveStorage trix image before record exist.

Forgot to mention, this is what Basecamp does when you create like a new Message. Same concept as writing a draft email in GMail too.

Adding this to my list for a screencast. 😜

Posted in Format of created_at for date range using Searchkick

It probably got flagged as spam cuz it was huge.

Important part of the error was this:

[400] {"error":{"root_cause":[{"type":"parse_exception","reason":"failed to parse date field []] with format [strict_date_optional_time||epoch_millis]"},

It looks like one of the date fields might not have been passed through.

Have you logged out your args var before it gets sent to Searchkick? I'm curious to see what that looks like. Usually you only want to include the field if it was present, and I don't see checks on that in your code for the date range fields. Maybe that is the issue.

Posted in ActiveStorage trix image before record exist.

I would probably recommend the middle option. One improvement you can make on that rather than deleting if the user cancels is to just have an idea of a "draft" record.

This would be a record you're editing but haven't fully published yet. It would only be visible to you and that way your images are attached to this record and you can safely delete them.

That helps in a lot of ways and also makes it so the user doesn't lose any progress as well which can be nice.

Posted in Format of created_at for date range using Searchkick

Can you post the error? I'm pretty sure it tells you which portion of the params was invalid.

It's been a while since I've done this, but I remember having to specify "range" or something.

Looks like you can do that: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html

Not sure if you can do it with Searchkick directly, so you'd have to ask them.

Yo, @kwiksource, I just updated the source code in the course. You can redownload it from the course to get the latest copy. 👍

Hey man! I'm gonna update this real quick. Working on a new version of the course as well that will come out in the next couple weeks.

I'll let you know when the code is updated. 👍