1

I want to save the text_field to database with defaut value ,but it's not work.

<p>
<%= f.label :用户id %><br>
<%= f.text_field :user_id ,:value => "#{current_user.try :id}", disabled: true %>
</p>
<p>
<%= f.label :用户昵称 %><br>
<% user = User.find current_user.id%>
<%= f.text_field :name ,:value => user.name , disabled: true%>
</p>
wind
  • 440
  • 4
  • 14

1 Answers1

2

Change disabled: true to readonly: true if you want the field to be un-editable but still submit a value.

"READONLY and DISABLED both remove the functionality of the input field, but to different degrees. READONLY locks the field: the user cannot change the value. DISABLED does the same thing but takes it further: the user cannot use the field in any way, not to highlight the text for copying, not to select the checkbox, not to submit the form. In fact, a disabled field is not even sent if the form is submitted."

Reference:

http://www.htmlcodetutorial.com/forms/_INPUT_DISABLED.html http://www.w3.org/TR/html4/interact/forms.html#h-17.12

Also see this answer: https://stackoverflow.com/a/7730719/2113461

Community
  • 1
  • 1
Nicholas.V
  • 1,926
  • 2
  • 15
  • 30