Chris Oliver

Joined

291,200 Experience
86 Lessons Completed
299 Questions Solved

Activity

Posted in Setup Windows 10 Discussion

It's likely that everything is installed but your terminal didn't automatically load rbenv again. Double check and make sure that you followed all the rbenv lines correctly to echo the lines into your .bashrc file.

For the select box, you can customize it to display user names using this: http://apidock.com/rails/v4...

Posted in Integrating Braintree (and PayPal) Discussion

You can definitely do that. What I would do is store the card on the user account after they pay the first time, and then the second time put in the existing card above the form and use JS to hide the Braintree form. This will let you use their existing card or toggle the Braintree form to use a different one.

You'll actually want to combine websockets with direct uploads (see: https://gorails.com/episode... ) in order to accomplish this. You don't want to upload files via websockets because they're not a good medium for this. Instead, you can upload files like you normally would and then you can use the response JSON from the upload to include the file in your application.

For example, Slack file uploads submit an AJAX file upload, you send over the message via ajax so you can upload the file and then once that's complete, it broadcasts it over websockets.

Awesome! :)

Posted in Direct File Uploads to S3: Part 3 Discussion

Great answer! :D

Posted in Direct File Uploads to S3: Part 3 Discussion

Should be very similar I would imagine although I haven't tried it.

Posted in Deploy Ubuntu 16.04 Xenial Xerus Discussion

You don't need to run Rails, Passenger will start the app for you automatically, that's why we set it up this way so you don't have to manage running scripts. It's automatic.

You're welcome and I'll definitely try to see about doing this as an episode moving forward. I think it'll be kinda tough to figure out a good example for this that really showcases the idea, but if you have any ideas I'm all ears! I tried doing this a couple times before but it's just one of those things I think you learn over time and kinda hard to appreciate until you've done it a few times.

So there isn't really anything specific other than I read the source code of gems. The undocumented details and important stuff is almost always hidden away inside the source for the gem unless it's a very popular gem.

For example to learn about Searchkick.models, I would just search the repository for models which I would assume would be a method somewhere inside the gem or a class variable and I'd start poking around that. The key with that would be figuring out what it does, how it's used, etc.

Today I was poking around the source code for docusign_rest to learn how it worked because I couldn't get some options passed over the API correctly. 15 seconds of looking at the source later, and I knew exactly what was wrong.

The thing with gems is realizing they're not a black box, they're just regular ruby code you would have written, but they're packaged up nicely for people to reuse, so you should always feel comfortable reading the source for that. It feels daunting at first, but honestly all the code in the gems is generally pretty much what you would have had to write to make the feature work if they didn't do it for you. Almost every time it's pretty logical when you dive into it, especially when you're curious about very specific bits like Searchkick.models as you don't have to understand how things work completed, just the small piece.

Posted in How do I add Ransack in my posts controller?

I believe exclusive would work as well. Doesn't really matter between those in this case.

Posted in How do I add Ransack in my posts controller?

Yeah, your link for about doesn't actually point to /about, it just points to / which means they're the same. You should match on exact for both of those. It would look like this I think:

# config/routes.rb
get "about", to: "pages#about"
root to: "pages#home"
<%= active_link_to "Home", root_path, :active => :exact %>
<%= active_link_to "About", pages_path, :active => :exact %>

Yeah in theory. I'm guessing that Business.current_id sets the tenant?

The callbacks for when you update a record are basically what you'd be tying into here. Anytime you update or delete a record, it needs to update or delete that item in the index. Rather than doing a bulk insert, you'll do them one by one so you can control the tenant stuff, which was the problem with the bulk imports because they couldn't handle the individual records.

You should keep your code then as if it were always in the proper tenant, so your model should look like it normally would:

class Product < ActiveRecord::Base
  belongs_to :department

  def search_data
    {
      name: name,
      department_name: department.name,
      on_sale: sale_price.present?
    }
  end
end

The reason for that is because this way you'll always be in the correct tenant, so you'll always be able to look up the department just fine.

Yeah, I guess if the reindex on a model clears the index before adding in the records, then that won't work.

However, then you should be able to go through each record and call reindex on it individually. That I know won't clear the index and so you could compile a full index of all the product records after looping through the tenants. It might be a tad slower on the initial index, but that's only going to happen the first time you index the full database. From then on, you'll be indexing things inside the app when changes are made so it should stay in sync just fine. And you won't need to do any of that department unscoped querying either. You can just access through the record directly.


On the unscoped part, you aren't calling a block there so I don't think you won't be running into that Rails bug.

Posted in How do I add Ransack in my posts controller?

It's one of those things that needs to be pretty customizable at times because sometimes you might have nested routes and want to match the parent or something, not the controller or action.

There's a nifty little gem I noticed in the answers there. https://github.com/comfy/active_link_to Looks like it would do a pretty good job allowing you to match most all of the variations you might need.

Hmm, I don't see what query block you're referring to? The unscoped method you use doesn't have a block and the issue more just stems from indexing the database where the tenant isn't set.

It looks like you've got the correct url for using the gem from github, although I don't think that's your problem. I don't see anywhere this is calling a block on the query, and your real issue is still probably the same as before. You're basically indexing but no tenant was ever set.

I think the solution for you is to build your own index rake task. You'd loop through each tenant, set the Apartment Tenant, and then index each of the records inside of it (rather than in bulk). Not sure why I didn't think of that before.

Based off https://www.tiagoamaro.com.br/2014/12/11/multi-tenancy-with-searchkick/ you could do something like this:

namespace :searchkick do
  desc 'Reindex all models on all tenants'
  task reindex_tenants: :environment do
    Rails.application.eager_load!

    Apartment::Tenant.each do |schema|
      Apartment::Tenant.switch!(schema)
      Searchkick.models.each do |model|
        puts "Reindexing #{model.name} on #{schema}"
        model.reindex
      end
    end
  end
end

This isn't modified from his code, except that you're not specifying separate indexes. This will set the tenant for each, it will find all the indexed models, and then it will also go and query for those records that are available. It'll do this once for each Tenant, which means it will find different sets of Product and Department records each time.

You will probably want to go back to using department_name: department.name, because you'll be in side the tenant this way. I believe this should do what you need because it's properly setting the tenant. Curious to see if that works for you.

Posted in How do I add Ransack in my posts controller?

You might need to set the URL on the form then so that it takes you to the index action. The search form may just normally only apply to the current url, I'm not sure.

Also that's a great idea. Like highlighting a link in the nav when you're on a certain controller right?

I'm kind of surprised that worked, but I guess there was something going on between the versions of Bundler that were local and previously installed in production. We both learned something new today. :) I'll have to keep this in mind as I'm sure I'm going to run into this as well sometime soon I bet.

And thanks man! Doing what I can, but it's just as much you and everyone else in the community who keeps it going, so thank you! 🙌

Super interesting bug there, especially since you aren't the only one. Potentially you need to upgrade your version of bundler? Let me know when you figure out a solution!

Hey Lance,

Interesting problem, I haven't actually run into this before. What does your Gemfile and Gemfile.lock look like for Nokogiri?

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.