Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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_Ruby_Views_Many To Many_Has And Belongs To Many - Fatal编程技术网

Ruby on rails 视图在一个有很多:通过关系

Ruby on rails 视图在一个有很多:通过关系,ruby-on-rails,ruby,views,many-to-many,has-and-belongs-to-many,Ruby On Rails,Ruby,Views,Many To Many,Has And Belongs To Many,我已经修补这个有一段时间了,但似乎无法解决这个问题。这可能很简单,但下面是: 我在“层压”和“标准”之间有一个多方面的关系,并加入了“标准化”模型 标准.rb 标准化.rb Laminate.rb 这个场景是层压板可以属于多个标准,我已经在视图的新部分中实现了所有功能-复选框和所有功能。我的问题是,当试图显示给定层压板的相应标准的名称时。到目前为止,我能够显示层压板指定给哪些标准,但不仅仅是标准的名称 My show.html.erb说: <%= @laminate.standards %

我已经修补这个有一段时间了,但似乎无法解决这个问题。这可能很简单,但下面是:

我在“层压”和“标准”之间有一个多方面的关系,并加入了“标准化”模型

标准.rb

标准化.rb

Laminate.rb

这个场景是层压板可以属于多个标准,我已经在视图的新部分中实现了所有功能-复选框和所有功能。我的问题是,当试图显示给定层压板的相应标准的名称时。到目前为止,我能够显示层压板指定给哪些标准,但不仅仅是标准的名称

My show.html.erb说:

<%= @laminate.standards %>
这会返回所有正确的结果,但是

 <%= @laminate.standards.name %>
。。。不起作用。我究竟怎样才能找到每一个人的名字呢

层压板控制器:

以下@Lamina.standards返回标准列表。此处调用名称无法工作,您应该在列表上执行每个循环:

# replace the following:
<%= @laminate.standards.name %>
# with this code:
<% @laminate.standards.each do |standard| %>
  <%= standard.name %>
<% end %>
如果您想要较短的版本,但不太可自定义:

<%= @laminate.standards.map{ |standard| standard.name }.join(', ') %>
# This will show all the standards' name with a coma-space ',' between it

# same a above but shorter:
<%= @laminate.standards.map(&:name).join(', ') %>
# this will call the 'name' method on each standard of @laminate.standards
# and join them with a coma-space
# something that would look like this:
# name1, name2, name3
以下@Lamina.standards返回标准列表。此处调用名称无法工作,您应该在列表上执行每个循环:

# replace the following:
<%= @laminate.standards.name %>
# with this code:
<% @laminate.standards.each do |standard| %>
  <%= standard.name %>
<% end %>
如果您想要较短的版本,但不太可自定义:

<%= @laminate.standards.map{ |standard| standard.name }.join(', ') %>
# This will show all the standards' name with a coma-space ',' between it

# same a above but shorter:
<%= @laminate.standards.map(&:name).join(', ') %>
# this will call the 'name' method on each standard of @laminate.standards
# and join them with a coma-space
# something that would look like this:
# name1, name2, name3

是的,是的,这里也是!非常感谢。是的,是的,这里也是!非常感谢。
# replace the following:
<%= @laminate.standards.name %>
# with this code:
<% @laminate.standards.each do |standard| %>
  <%= standard.name %>
<% end %>
<%= @laminate.standards.map{ |standard| standard.name }.join(', ') %>
# This will show all the standards' name with a coma-space ',' between it

# same a above but shorter:
<%= @laminate.standards.map(&:name).join(', ') %>
# this will call the 'name' method on each standard of @laminate.standards
# and join them with a coma-space
# something that would look like this:
# name1, name2, name3