is this something Rails has built in or would i need to set the fleet_type manually by checking if a Car or Train was created?
For a couple of days now i am going back and forth how to models this.
I currently have the following model structure and relations (simplified)
class Fleet < ApplicationRecord # properties id, created_at, updated_at # A fleet should only consists of the same type, either a fleet or cars or a fleet of trains. Never both has_many :cars has_many :trains end class Car < ApplicationRecord # properties id, created_at, updated_at, number_of_gears, is_sports_car belongs_to :fleet end class Train < ApplicationRecord # properties id, created_at, updated_at, number_of_wagons, people_capacity, has_first_calass_section belongs_to :fleet en
The problem i have is thata fleet should only consists of the same type, either a fleet of cars or a fleet of trains. Never both.
With the current relations on fleet, it seems error prone to have both has_many associations (or more coming like Airplanes) in terms of integrity and ease of use when calling @fleet._cars-or-trains, i would have to know what i can call.
STI is not an option since the properties are very different on a Car and a Train. There are many more properties, for the sake of simplicity i have shortened them in this example.
What is the right way in Rails to do this?
Do you loop through all the rooms also on the client side and call
App.cable.subscriptions.create for each channel or is there a more straight forward way like subscribing to multiple channels at once?
How do you subscribe on the client to multiple rooms ?
All examples i can find are subscribing to one single room by pasing a room as a param when creating the channel but what if i have Room A, B and C an i (as a user) am in all of them.
This is an example with one room http://edgeguides.rubyonrails.org/action_cable_overview.html#client-server-interactions-subscriptions
Yeah i will probably do that because i can get away with it. It's a internal chat but for public ones like Slack that wouldn't work well. Performance would be a problem when storing all of that in the DOM.
I checked out Slack and it does not have all of the chat rooms inside the DOM. There is no local storage too so my best guess is that it stores it inside a JS variable in memory and it fills a single chat room DOM node when you click the rooms.
What approach would you take on the client side? When you have 5 chat rooms but you are only viewing one at a time, where would you store the messages of the other 4 so when you select another channel to view, you don't have to query the db every time.
anime.season.update(title: "Spring 2015")
A cast about how to do authorization with ActionCable. Example is a Chat with multiple chat rooms and messages should only be sent to rooms / people who have access to the given chat room.