Frenchy Frenchy - 7 months ago 84
HTML Question

Ruby On Rails getting the error: syntax error, unexpected keyword_ensure, expecting end-of-input

I'm somewhat new to ruby on rails and i'm working on nesting models for a web app i'm working on which will have goals which have steps assigned to them.

I'm working on creating a form nested with nested goals and steps but i am getting the error

"syntax error, unexpected keyword_ensure, expecting end-of-input"

<% 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 %>

Answer

You have added extra <% end %> and your form should be <%= form ..... %> not <% form .... %>

Try to replace your above code with this:

<%= 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 %>