Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 显示属于表国家/地区的表商店数据,在国家/地区视图中显示_Ruby On Rails - Fatal编程技术网

Ruby on rails 显示属于表国家/地区的表商店数据,在国家/地区视图中显示

Ruby on rails 显示属于表国家/地区的表商店数据,在国家/地区视图中显示,ruby-on-rails,Ruby On Rails,我使用的是Rails 2.3.8。我在该表中列出了以下数据: 数据库表 在shop.rb中,我把它放在:country 在我所在国家的view.html.erb中,我希望能够显示Shops表中的相关注释。这种情况下,在页面中http://localhost:3000/countries/10,店铺ID1和ID2的注释应显示在此页面中 有人能告诉我如何做到这一点吗?非常感谢。您还需要添加country.rb有很多:商店。现在,从html你可以 <% country.shops.each do

我使用的是Rails 2.3.8。我在该表中列出了以下数据:

数据库表

在shop.rb中,我把它放在:country

在我所在国家的view.html.erb中,我希望能够显示Shops表中的相关注释。这种情况下,在页面中http://localhost:3000/countries/10,店铺ID1和ID2的注释应显示在此页面中


有人能告诉我如何做到这一点吗?非常感谢。

您还需要添加country.rb有很多:商店。现在,从html你可以

<% country.shops.each do |shop| %>
  <%= shop.notes %>
<% end %>

通过添加has\u many,您可以使关系双向,并且您可以导航到from shop->country或from country->shops。

您还需要添加country.rb has\u many:shops。现在,从html你可以

<% country.shops.each do |shop| %>
  <%= shop.notes %>
<% end %>
通过添加has\u many,您可以使关系双向,并且您可以导航到from shop->country或from country->shops。

您需要将has\u many:shops放在您的国家/地区模型中

在你看来,你可以环游商店

希望这能有所帮助。

您需要在您的国家/地区建立多家店铺

在你看来,你可以环游商店


希望这能有所帮助。

谢谢奥古斯托。很抱歉,我只能接受一个答案。所以我会接受拉法的回答,考虑到他先做了回答。我还是很感激,谢谢奥古斯托。很抱歉,我只能接受一个答案。所以我会接受拉法的回答,考虑到他先做了回答。我仍然心存感激。