从另一个表单内部向一个表单提交信息

时间:2011-12-22 16:26:16

标签: ruby-on-rails forms html-table form-for

我有以下显示的灯具列表,并希望在selection.winner和selection.value字段的位置输入选择字段,并将它们发送到@selection而不是@gameweek。有没有办法做到这一点?

这两个型号的设置如下:
用户:用户名,电子邮件,encrypted_pa​​ssword,salt,created_at,updated_at
TEAMS:name,created_at,updated_at
固定:date,home_team,away_team,weekno,result,winner,created_at,updated_at
GAMEWEEKS:数字,匹配,截止日期,created_at,updated_at
选择:userid,gameweekno,fixtureno,winner,value,created_at,updated_at

例如,是否有任何简单的方法可以将赢家[Home,Draw,Away]和Value [1..10]与相应的userid,gameweekno和fixtureno一起保存到Gameweek /中的选择表中17 /编辑我目前保存表格的URL

<%= form_for(@gameweek) do |f| %>
  <% if @gameweek.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@gameweek.errors.count, "error") %> prohibited this gameweek from being saved:</h2>

      <ul>
      <% @gameweek.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

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

<h1>Gameweek <%= @gameweek.number %></h1>

<p>
  <b>Number of matches:</b> 
  <%= @gameweek.matches %>
  <b>Deadline Date:</b>
  <%= @gameweek.deadline.strftime("%d/%m/%Y") %>
  <b>Deadline Time:</b>
  <%= @gameweek.deadline.strftime("%H:%M") %>
</p>

<table width="100">
  <tr>
    <th>Date</th>
    <th>Kick Off</th>
    <th>Home</th>
    <th></th>
    <th>Away</th>
    <th>Result</th>
    <th>Prediction</th>
    <th>Value</th>
  </tr>

<% Fixture.where(:weekno => @gameweek.number).each do |fixture| %> 
  <tr>
    <td width="10"><%= fixture.date.strftime("%d/%m/%Y")%></td>
    <td width="10"><%= fixture.date.strftime("%H:%M") %></td>
    <td width="80"><%= fixture.home_team %></td> 
    <td width="10">Vs.</td>
    <td width="80"><%= fixture.away_team %></td>
    <td width="10"><%= fixture.result %></td>
    <% user_selections = Selection.where(:userid => current_user.id, :fixtureno => fixture.id) %> 
    <% if user_selections.empty? %>   
        <td width="10">Pending</td> 
        <td width="10">Pending</td> 
    <% else %>   
        <% user_selections.each do |selection| %>     
            <td width="10"><%= selection.winner %></td>            
            <td width="10"><%= selection.value %></td>     
        <% end %> 
    <% end %>       
  </tr>
<% end %>
</table>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

0 个答案:

没有答案