Ruby on rails 将表单标记转换为简单表单
我将如何将下面的表单标记转换为的表单_Ruby on rails 将表单标记转换为简单表单,ruby-on-rails,ruby,Ruby On Rails,Ruby,我将如何将下面的表单标记转换为的表单_ <%= form_tag(contact_email_path, :method => 'post') do %> <%= label_tag "Your email" %> <%= text_field_tag "sender", @sender, :autofocus => true %> <%= label_tag "Subject" %> &
<%= form_tag(contact_email_path, :method => 'post') do %>
<%= label_tag "Your email" %>
<%= text_field_tag "sender", @sender, :autofocus => true %>
<%= label_tag "Subject" %>
<%= text_field_tag "subject", @subject %>
<%= label_tag "Message" %>
<%= text_area_tag "message", @message %>
<%= submit_tag "Send Email" %>
<% end %>
“post”)do%>
正确%>
表单\u for
是创建创建或编辑资源的表单的助手
如果您希望在数据库中创建一个资源,则可以使用此方法。看起来您在这里所做的不是创建资源,而是发送电子邮件。如果是这样,那么form_标签
可能是更好的选择
但是,如果您试图在数据库中创建新资源(即ContactEmail
或其他类的新实例),则可以这样做:
<%= form_for @contact_email do |f| %>
<%= f.label :sender, "Your email" %>
<%= f.text_field :sender, :autofocus => true %>
<%= f.label :subject %>
<%= f.text_field :subject %>
<%= f.label :message %>
<%= f.text_area :message %>
<%= f.submit "Send Email" %>
<% end %>
正确%>
这假设
@contact\u email
是一个对象,具有方法发送者
、主题
和消息
,并且您的路由文件中有资源:contact\u email
。您击败了某人+1.