Building my app was going well until it came time to render attributes of a model in relation to another model.
In Ruby, the relationships are set up like so and through naming conventions it knows where to look for whatever it’s looking for. Here, I have 3 models in a many-to-many relationship.
class Review < ApplicationRecord belongs_to :user belongs_to :wine end class User < ApplicationRecord has_many :reviews has_many :wines, through: :reviews end class Wine < ApplicationRecord has_many :reviews, :dependent => :destroy has_many :users, through: :reviews end
In a Rails app, to create the frontend I would just need to create html.erb files within a folder (within app/views folder) that correlates with the above models by sharing the same name (naming convention). Then, in the controller actions I would just need to specify what to render. Through naming convention of the files, Rails automatically (almost magically) knows what is linked to what and therefore what to render.
So, in the controller actions I need to tell the app what to render (via ‘render json:’ then whatever specified to render).