ruby on rails - Show value if exists within text_field_tag -


i have form using form_tag allows users input prediction football match, fixtures taken separate model..what once have submitted predictions, next time view same form predictions prepopulated against fixtures whist having input field readonly..

form looks so

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

i had thought disabling text input using

 :disabled => true 

but seems return input text

{:disabled => true} 

so once user has made prediction these 2 inputs prepopulated prediction

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

can point me in right direction please

thanks

edit

i know why disabled => true outputs {}, docs seems if disabled option takes previous statement argument/value.. if this

'', :disabled => true

then blank text_field

you see text input {:disabled => true} text because text_field_tag accepts 3 arguments: name, value, , options. if not specify value explicitly, supposes {:disabled => true} it. change code following:

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

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -