我需要Rails中的textfield:
<%= f.text_field :first_name, autofocus: true, placeholder: :first_name , :class => 'form-control', "disabled" => "disabled" %>
我想在一个文本字段中显示两个变量:
:first_name :second_name
怎么做?
答案 0 :(得分:2)
您应该在模型中建立一个连接first_name
和second_name
的方法:
def full_name
"#{self.first_name}, #{self.second_name}"
end
然后在你的视图中调用它:
<%= f.text_field :full_name, autofocus: true, placeholder: :first_name , :class => 'form-control', "disabled" => "disabled" %>
答案 1 :(得分:0)
<%= f.text_field :first_name, value: "#{f.object.first_name} #{f.object.second_name}", autofocus: true, placeholder: :first_name , :class => 'form-control', "disabled" => "disabled" %>