I am trying to create an association between 3 models where 1 of the models has an association with the other 2 but they have no association with each other. I thought I was one the right track and can create data for the 2 models (breweries and restaurants) but cannot get the third model(beers) to correctly save when used in localhost and will not associate with any other models.
The models are
class Beer < ActiveRecord::Base belongs_to :brewery belongs_to :restaurant validates :brewery, presence: true validates :restaurant, presence: true validates :name, presence: true end
class Brewery < ActiveRecord::Base has_many :beers validates :name, presence: true end
class Restaurant < ActiveRecord::Base has_many :beers validates :name, presence: true end
I also get an error whenever I try to create a new beer through the local host
Error Message This is referring to the beers_controllers method.
def create @brewery = Brewery.find(params[:brewery_id]) @beer = @brewery.beers.create(beer_params) redirect_to @beer end
I've tried everything I can think of to no avail and am worried it's just a syntax error that I'm over looking. Would love any advice. Thanks.
Aucun commentaire:
Enregistrer un commentaire