Posted in Override CSS in Gem with CSS from app
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?
Posted in Rails Association Question
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
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.