Chris Oliver

Joined

290,710 Experience
86 Lessons Completed
298 Questions Solved

Activity

Posted in Direct File Uploads to S3: Part 3 Discussion

The missing semicolons are okay, the browser handle that just fine. The missing ) doesn't sound right, because that would actually cause the JS to break if that were the case. That could be breaking your code by adding that in, or you've got an extra opening ( somewhere.

I updated the file with the semicolons for ya: https://github.com/gorails-...

Posted in Pull data from another table in a lookup

Agreed Jacob!

And yeah you're right about the HABTM table name. The thing about HABTM is that you don't get to ever interact with that table in the middle...so imagine you needed some meta data, like a quantity of the product in each venue...well you're SOL with HABTM. If you have an explicit model as a join table, and do has_many through, then you can add extra columns in like a quantity and do a whole lot more with it. In most cases I find it's better to be explicit about that join table than using HABTM for that reason. Guess I should do an episode on this!

Posted in Pull data from another table in a lookup

Oh I gotcha now! Yeah that makes sense. So then you are correct having both the venue_id and product_id on that table. The naming I believe is what threw you off because you actually need a bunch of records of the BackBar per venue.

class BackBar < ApplicationRecord
  belongs_to :product
  belongs_to :venue
end
class Product < ApplicationRecord
  has_many :back_bars
  has_many :venues, through: :back_bars
end
class Venue < ApplicationRecord
  has_many :back_bars
  has_many :products, through: :back_bars
end
# controller
@products = @venue.products

Posted in Pull data from another table in a lookup

Yeah, for a many-to-many relationship, you'll actually need a join table and has_and_belongs_to_many will use that to connect everything. Thats the only way for your backbar to have many products and your products to belong to many backbars.

Posted in Pull data from another table in a lookup

Yeah, sounds like your relationship is backwards in the database where a BackBar belongs_to :product, when it should actually be a Product belongs_to :back_bar.

Depending on what you want to do now, you can use something like this to work with their API: https://github.com/gimite/google-drive-ruby

You'll just pass in the access token you received from omniauth into this library to hit their API.

Posted in Setup Windows 10 Discussion

I used rbenv just fine when I initially set things up. My Windows 10 install got corrupted so I need to reinstall it and try this again sometime to see how things have changed.

Posted in Pull data from another table in a lookup

If I'm following correctly, I think your query @venue.backbar.products is what is causing that. If you have a has_many :products on BackBar, then you also need the back_bar_id on the Product table to associate them.

Posted in Group Chat with ActionCable: Part 2 Discussion

You would want something like this:

add_index(:chatroom_users, [:chatroom_id, :user_id], unique: true)

Can you share your whole file?

What are you having trouble with? The if statements around your code should be mostly the same.

Posted in store_accessor with jsonb nesting

Honestly, I think you're better off using this than trying to build your own implementation. It'll let you set defaults and types for each attribute which will make it significantly easier to work with: https://github.com/devmynd/jsonb_accessor

The types are going to be a problem when you start using forms because they won't automatically be cast to booleans, etc. That makes for a mess.

You shouldn't need the HashSerializer because that's what store_accessor implements for you. It doesn't do with indifferent access, but it will convert back and forth from jsonb to a hash.

To set defaults, just setup a default value after initialize:

class Foo < ApplicationRecord
  store_accessor :permits, :bar_permit, :baz_permit

  after_initialize :set_defaults

  def set_defaults
    self.permits ||= {
      bar_permit: {
        key1:      [],
        key2:       "Bar",
        key3:       false,
        key4:       false,
        key5:       false
      },
      foobar_permit: {
        key1:      [],
        key2:       "Bar",
        key3:       false,
        key4:       false,
        key5:       false
      }
    }
  end
end

This tool can translate to and from Coffeescript: http://js2.coffee/ 👍

Posted in why .limit not working with find_by

You're welcome! Thanks for being here! :D

Posted in Exporting Records To CSV Discussion

It's not an Array, it's an ActiveRecord::Relation object. They act like Arrays, but are very different.

Posted in Is there a better way to simplify this?

You can customize it, but that's the inferred default name.

Posted in Direct File Uploads to S3: Part 3 Discussion

Might want to undo that? I'm not sure.

Posted in Direct File Uploads to S3: Part 3 Discussion

Absolutely, glad you enjoyed it! :)

Posted in Direct File Uploads to S3: Part 3 Discussion

If you're getting the fileupload is not a function, then maybe jquery fileupload is not included in your application.js file?