[英]Ruby On Rails getting the error: syntax error, unexpected keyword_ensure, expecting end-of-input
我对 ruby on rails 有点陌生,我正在为我正在处理的 Web 应用程序构建嵌套模型,该应用程序将具有分配给它们的目标的目标。
我正在创建一个嵌套有嵌套目标和步骤的表单,但出现错误
“语法错误,意外的keyword_ensure,期望输入结束”
<% form_for @goal do |goal_form| %>
<div>
<%= goal_form.label :Goal, 'Goal:' %>
<%= goal_form.text_field :Goal %>
</div>
<div>
<%= goal_form.label :Description, 'Description:' %>
<%= goal_form.text_area :Description %>
</div>
<div>
<%= goal_form.label :Date, 'Date:' %>
<%= goal_form.date_select :Date %>
</div>
<div>
<%= goal_form.label :DueDate, 'DueDate:' %>
<%= goal_form.date_select :DueDate %>
</div>
<!-- Here we call fields_for on the project_form builder instance.
The block is called for each member of the tasks collection. -->
<% goal_form.fields_for :steps do |step_form| %>
<p>
<div class="field">
<%= step_form.label :requirement %><br>
<%= step_form.text_field :requirement %>
</div>
<div class="field">
<%= step_form.label :completionTime %><br>
<%= step_form.number_field :completionTime %>
</div>
<% unless step_form.object.new_record? %>
<div>
<%= step_form.label :_delete, 'Remove:' %>
<%= step_form.check_box :_delete %>
</div>
<% end %>
</p>
<% end %>
<% end %>
<div class="actions">
<%= goal_form.submit %>
</div>
<% end %>
您添加了额外的<% end %>
并且您的表单应该是<%= form ..... %>
而不是<% form .... %>
尝试用以下代码替换上面的代码:
<%= form_for @goal do |goal_form| %>
<div>
<%= goal_form.label :Goal, 'Goal:' %>
<%= goal_form.text_field :Goal %>
</div>
<div>
<%= goal_form.label :Description, 'Description:' %>
<%= goal_form.text_area :Description %>
</div>
<div>
<%= goal_form.label :Date, 'Date:' %>
<%= goal_form.date_select :Date %>
</div>
<div>
<%= goal_form.label :DueDate, 'DueDate:' %>
<%= goal_form.date_select :DueDate %>
</div>
<!-- Here we call fields_for on the project_form builder instance.
The block is called for each member of the tasks collection. -->
<% goal_form.fields_for :steps do |step_form| %>
<p>
<div class="field">
<%= step_form.label :requirement %><br>
<%= step_form.text_field :requirement %>
</div>
<div class="field">
<%= step_form.label :completionTime %><br>
<%= step_form.number_field :completionTime %>
</div>
<% unless step_form.object.new_record? %>
<div>
<%= step_form.label :_delete, 'Remove:' %>
<%= step_form.check_box :_delete %>
</div>
<% end %>
</p>
<% end %>
<div class="actions">
<%= goal_form.submit %>
</div>
<% end %>
<%= form_for @goal do |goal_form| %>
<div>
<%= goal_form.label :Goal, 'Goal:' %>
<%= goal_form.text_field :Goal %>
</div>
<div>
<%= goal_form.label :Description, 'Description:' %>
<%= goal_form.text_area :Description %>
</div>
<div>
<%= goal_form.label :Date, 'Date:' %>
<%= goal_form.date_select :Date %>
</div>
<div>
<%= goal_form.label :DueDate, 'DueDate:' %>
<%= goal_form.date_select :DueDate %>
</div>
<!-- Here we call fields_for on the project_form builder instance.
The block is called for each member of the tasks collection. -->
<% goal_form.fields_for :steps do |step_form| %>
<p>
<div class="field">
<%= step_form.label :requirement %><br>
<%= step_form.text_field :requirement %>
</div>
<div class="field">
<%= step_form.label :completionTime %><br>
<%= step_form.number_field :completionTime %>
</div>
<% unless step_form.object.new_record? %>
<div>
<%= step_form.label :_delete, 'Remove:' %>
<%= step_form.check_box :_delete %>
</div>
<% end %>
</p>
<% end %>
<div class="actions">
<%= goal_form.submit %>
</div>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.