gpt4 book ai didi

ruby-on-rails - 如果存在于 text_field_tag 中则显示值

转载 作者:数据小太阳 更新时间:2023-10-29 08:38:57 24 4
gpt4 key购买 nike

我有一个使用 form_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]" %>

谁能给我指出正确的方向

谢谢

编辑

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

'', :disabled => true

然后我得到一个空白的text_field

最佳答案

您看到带有 {:disabled => true} 文本的文本输入,因为 text_field_tag 接受三个参数:namevalue 选项。如果您没有明确指定 value,它会假设 {:disabled => true} 就是它。因此,将您的代码更改为以下内容:

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

关于ruby-on-rails - 如果存在于 text_field_tag 中则显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16633683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com