Neil Tonge

Joined

320 Experience
1 Lesson Completed
0 Questions Solved

Activity

Posted in How to use Dev Containers with Rails Discussion

Amazing! Will give it a shot!

Posted in How to use Dev Containers with Rails Discussion

Are these ok to use day to day for development? Ie, can I switch my app to work in a devcontainer and just use that from here on out?

I have a lot of files already on Backblaze B2 (S3 compatible) that I wish to use with ActiveStorage. The problem is, the majority of my sites data gets populated and updated by wiping it all out and being reimported by way of an Excel document and an import script.

Basically for this app, the truth is in a spreadsheet, I KNOW it's not ideal but that's the way it is here for this app.

I do not wish to download all my files each time I do a reimport.

Therefore I am writing a rake task that creates the appropriate ActiveStorage records and associates them with the correct model instances after an import. This MOSTLY works fine. It does create everything but it then comes to analysing and it says with ActiveStorage::IntegrityError. I'm not 100% sure but I assume this is something to do with the checksum?

Currently my task can be viewed here: https://gist.github.com/rctneil/7e275e74c66dd7a6ffc804ff1d740121

Any suggestions to how I can get the analysing done and the Integrity Error to be resolved?

Thanks!

Posted in Override CSS in Gem with CSS from app

Hi,

I'm working on a Rails Gem. The gem provides one view and a basic stylesheet for it.

When installed in an app, i'd like to be able to override the basic styles with other styles in the app itself. How can this be done? I'm confused as i'm not sure how to link the new styles to the view when the view is part of the gem. I don't wish to duplicate the view into the app though. Just wish to write an override set of styles and have that apply to that one view template.

I was thinking about somehow specifying a config option where a path to a file can be set, and if this is configured then it will conditionally show in the view. Is this the right approach or is there a better way?

Thanks,
Neil

Posted in Rails Association Question

Hello

I have an app where I have a list of Cars. I have a form above that can filter them based on different attributes. I wish to add filtering based on their model and sub-models.

Each car already has a Manufacturer and these have models and then sub-models.

How can I structure this in Rails? Do I have a Modell and a SubModell (using those names to stop conflicting with rails own naming). or is there a better way?

I wish to be able to return the Manufacturer and Model and Sub Model directly from a car though. Like so:

c = Car.first
c.manufacturer # => "Ford"
c.model # => "Mondeo"
c.sub_model # => "Estate"

I need this to be able to allow adding Cars where I know the Manufacturer but not the Model or Sub Model.

Is this possible?

Neil, Thanks in advance

Posted in Finding records using Delegated Types

Hi,

I have a Delegated Types association set up like below and I need to find a particular Collection but the flickr_id is stored in the GalleryItem table. It's failing to return anything. How can I get the following line to work?

collection = Collection.find_by(flickr_id: flickr_collection.id)

-

class Collection < ActiveRecord::Base
    include GalleryItemable
end

-

class Album < ActiveRecord::Base
     include GalleryItemable
end

-

module GalleryItemable
    extend ActiveSupport::Concern

    included do
        has_one :gallery_item, as: :gallery_itemable, touch: true, dependent: :destroy
    end
end

-

class GalleryItem < ActiveRecord::Base
    belongs_to :collection, optional: true
    belongs_to :album, optional: true
    delegated_type :gallery_itemable, types: %w[ Collection Album ], dependent: :destroy

    acts_as_list scope: :collection
end

I hope someone can help.

Thanks,
Neil