Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set value on textfield

In my application I want set value to textfield. I want to do same like here

<input type="text" value ="something">

My question how could i do the same on rails view.

   <h1>New location</h1>

<% form_for(@location) do |f| %>
  <%=  f.error_messages %>

  <p>
    <%= f.label :address %><br />
    <%=  f.text_field :address %>

  </p>
  <p>
    <%= f.label :latitude %><br />
    <%= f.text_field :latitude %>
  </p>
  <p>
    <%= f.label :longitude %><br />
    <%= f.text_field :longitude %>
  </p>
  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

<%= link_to 'Back', locations_path %>

1 Answers

By passing the value argument

<%= f.text_field :latitude, :value => 17 %>
like image 153
Kulbir Saini Avatar answered Feb 20 '26 19:02

Kulbir Saini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!