Ruby on rails 处理ID';她与许多人有联系

Ruby on rails 处理ID';她与许多人有联系,ruby-on-rails,Ruby On Rails,我正在制作一个控制电视节目的节目,所以我的关系是:Show有很多季,而季有很多集 我不知道如何通过季节表的show.id,我的一个朋友帮助了我,但我不理解他的方法。当我试着用同样的方法来传递季号时,我却不能。下面是代码: 季节控制员 def create @season = Season.new(season_params) if session[:id] != nil @season.show_id = (session[:id]) session[:id] = nil end

我正在制作一个控制电视节目的节目,所以我的关系是:
Show
有很多
,而
有很多

我不知道如何通过季节表的
show.id
,我的一个朋友帮助了我,但我不理解他的方法。当我试着用同样的方法来传递
季号
时,我却不能。下面是代码:

季节控制员

def create
  @season = Season.new(season_params)
  if session[:id] != nil
  @season.show_id = (session[:id])
  session[:id] = nil
end
显示节目视图(我选择了一个坏名字)。 从这个角度来看,我希望看到所有与该剧相关的季和集

<p id="notice"><%= notice %></p>
<% @seasons = Season.all %>

<% @seasons.where(:show_id => @show.id).each do |season| %>
<tr>
  <td><%= season.order %></td>
  <td><%= season.status %></td>
</tr>
<% end %>
<%= link_to 'create seasons', season_new_path(@show.id) %>
<%= link_to 'Edit', edit_show_path(@show) %> |
<%= link_to 'Back', shows_path %>
是否有更好的方法来传递
show.id
season
id和
season.id
的插曲id

我忘了在另一台电脑上推送我为这一集编写的代码


如果您想查看更多代码,请查看my github:

添加
接受
中季节的嵌套属性

new.html.erb,应如下所示

<% form_for @show do |f| %>
    <%= f.error_messages %>
    <% f.fields_for :seasons do |s| %>
        <p>
            <%= s.label :order, "Order" %><br />
            <%= s.text_field :order %>
        </p>
        <p>
            <%= s.label :status, "Status" %><br />
            <%= s.text_field :status %>
        </p>
    <% end %>
    <p><%= f.submit "Submit" %></p>
<% end %>   




show.html.erb

<p id="notice"><%= notice %></p>

<% for season in @show.seasons %>
     <td><%= season.order %></td>
     <td><%= season.status %></td>
<% end %>

<%= link_to 'create seasons', season_new_path(@show) %>
<%= link_to 'Edit', edit_show_path(@show) %> |
<%= link_to 'Back', shows_path %>

|
您可以尝试使用
accepts\u nested\u attributes\u作为方法
太好了,我不知道这个方法接受嵌套的属性。但是,如果我还想显示每一季的剧集,我不能在show模型中使用accepts_nested_attributes_for:剧集。或者我可以使用accepts_nested_attributes_for:Sessions in season model,并使用@show.seasons.Sessions?抱歉,问题太多了,我在rails的开头有点迷路了,那就是new.html.erb,是来自season的视图吗?因为我已经有了一个新的show.html.erb,它创建了show。因此,如果是在季节视图中,我如何知道@show的id在单击createshow后是相同的。不知道我是否清楚。
<p id="notice"><%= notice %></p>

<% for season in @show.seasons %>
     <td><%= season.order %></td>
     <td><%= season.status %></td>
<% end %>

<%= link_to 'create seasons', season_new_path(@show) %>
<%= link_to 'Edit', edit_show_path(@show) %> |
<%= link_to 'Back', shows_path %>