Nested URLs, controllers and views in Ruby on Rails

主宰稳场 提交于 2019-12-25 08:46:47

问题


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.


回答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.



来源:https://stackoverflow.com/questions/44906304/nested-urls-controllers-and-views-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!