Reputation: 1755
I need textfield in Rails:
<%= f.text_field :first_name, autofocus: true, placeholder: :first_name , :class => 'form-control', "disabled" => "disabled" %>
I want to display two variables in one text field:
:first_name :second_name
How to do this?
Upvotes: 0
Views: 120
Reputation: 2654
You should have in you model a method that concatenates first_name
and second_name
:
def full_name
"#{self.first_name}, #{self.second_name}"
end
And then call it in you view like that:
<%= f.text_field :full_name, autofocus: true, placeholder: :first_name , :class => 'form-control', "disabled" => "disabled" %>
Upvotes: 2
Reputation: 2040
<%= f.text_field :first_name, value: "#{f.object.first_name} #{f.object.second_name}", autofocus: true, placeholder: :first_name , :class => 'form-control', "disabled" => "disabled" %>
Upvotes: 0