Ruby on Rails中的嵌套URL,控制器和视图 [英] Nested URLs, controllers and views in Ruby on Rails
问题描述
我想做的是例如将页面嵌套在Rails中:
What I am trying to do is to nest my pages in Rails for example:
www.mysite.com/fifa17/ps4
这样,一旦我进入 show.html.erb ,就可以使用该途径在该控制台平台上专门为该游戏销售产品.
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..
目前,我有一个带有has_many :games
的Console
模型和一个带有has_many :consoles
的Game
模型,但是我无法使用路由和视图.我只有一个或两个控制器吗?
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?
我将Games
和Consoles
都植入了name
在 ActiveRecords 下.
我似乎可以调用其中一个操作(即Console.name
),但不能同时调用控制台名称和游戏名称.
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.
推荐答案
在Ruby on Rails上阅读此书的好地方关联指南和路由指南.
A great place to read on this would be in Ruby on Rails Associations Guide and Routing Guide.
您想要做的是更新您的Console
和Game
关联,以使用has_and_belongs_to_many
.您可以在此处中阅读更多内容
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
并仔细检查您的路由,检查此 StackOverflow问题用于类似情况.
And double check your routing, check this StackOverflow Question for a similar case.
这篇关于Ruby on Rails中的嵌套URL,控制器和视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!