2013-05-19 25 views
2

我有一个form_tag表单,它允许用户输入一个足球比赛的预测,这些灯具取自一个单独的模型。我想要做的是一旦他们提交了他们的预测他们查看相同的形式他们的预测预填充对灯具惠斯特为只读具有输入领域的下一次..如果text_field_tag中存在值,则显示值

的形式看起来像这样

<%= form_tag controller: 'predictions', action: 'create', method: 'post' do %> 
     <% @fixture_date.sort.each do |date, fixture| %> 
      <ul class="fixture-dates"> 
      <li><h5><%= date_format(date) %></h5></li> 
      </ul> 

      <ul class="fixtures"> 
       <% fixture.each do |fixture|%> 
       <% if current_user.predictions.where(:fixture_id == fixture.id).empty? %> 
       <li> 
        <span class="home-team"><%= fixture.home_team %></span> 
        <span class="score"> 
        <%= text_field_tag "predictions[][home_score]" %> 
        <%= text_field_tag "predictions[][away_score]" %> 
        </span> 
        <span class="away-team"><%= fixture.away_team %></span> 
       </li> 
       <%= hidden_field_tag "predictions[][home_team]", fixture.home_team %> 
       <%= hidden_field_tag "predictions[][away_team]", fixture.away_team %> 

       <%= hidden_field_tag "predictions[][fixture_date]", fixture.fixture_date %> 
       <%= hidden_field_tag "predictions[][fixture_id]", fixture.id %> 

       <% else %> 
       pre populated predictions against fixtures here 
       <% end %> 

       <% end %><!--if statement --> 

       </ul> 
     <% end %> 
      <%= submit_tag "Submit predictions", :class => "btn btn-success btn-large" %> 
     <% end %> 

我曾想过使用禁用的

文本输入
:disabled => true 

但这似乎只是这个文本

{:disabled => true} 

所以返回输入一旦用户做出了他们的预测是,我想用自己的预测预填充这两个输入

<%= text_field_tag "predictions[][home_score]" %> 
<%= text_field_tag "predictions[][away_score]" %> 

请问谁能指点我的方向正确

谢谢

ED IT

我现在知道为什么禁用=>真正的输出{},从文档看来,如果禁用选项将前面的语句作为它的参数/值..所以如果我这样做

“ ”:禁用=>真

然后我得到了一个空白text_field

回答

4

你看到{:disabled => true}文本的文本输入,因为text_field_tag接受三个参数:namevalueoptions。如果您未明确指定value,则假设为{:disabled => true}。所以,你的代码更改为以下:

<%= text_field_tag "predictions[][home_score]", nil, :disabled => true %> 
+0

感谢,所以在地方零例如,如果一个已经取得了我可以通过用户的预测? – Richlewis

+0

@Richlewis当然你可以 –

+0

即时通讯试图访问用户使用current_user.predictions.home_score,:disabled => true,但不能访问评分 – Richlewis

相关问题