0

What I am trying to do is to nest my pages in Rails for example:

www.mysite.com/fifa17/ps4

This way, once I am on the show.html.erb, I can use use the route to sell my product for specifically that game on that console platform..

At the moment, I have a Console model with has_many :games and a Game model with has_many :consoles, but I can't get the routing and views to work. Do I have just one controller or two?

I have both the Games and Consoles seeded under ActiveRecords by name. I seem to be able to call one of the actions (i.e. Console.name) but cannot call both the console name and Game name.

4
  • Start with changing the associations. Seems like it is a case of HMT or HABTM Commented Jul 4, 2017 at 12:45
  • Update the question with Game and Console models. Commented Jul 4, 2017 at 12:50
  • Your models should be using has_and_belongs_to_many. (Or has_many through: your_join_table). Commented Jul 4, 2017 at 13:17
  • use has many through, do not use has and belongs to many. Commented Jul 4, 2017 at 14:15

1 Answer 1

1

A great place to read on this would be in Ruby on Rails Associations Guide and Routing Guide.

What you want to do, is to update your Console and Game associations, to use has_and_belongs_to_many. You can read more on that here

And double check your routing, check this StackOverflow Question for a similar case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.