Rails syntax unexpected keyword_do_block

2019-09-01 02:15发布

问题:

Im getting a 'syntax error, unexpected keyword_do_block, expecting keyword_end ... form_for[@event, @document] do |f| @output_buffer.safe_appe... ... ^ ' and 'syntax error, unexpected keyword_ensure, expecting end-of-input'

I trying to add a document submitting form to another page in my project. Is the form_for written incorrectly??

<div class="span5">
  <div class="span8">
    <h3>Event Files</h3>
      <%= form_for[@event, @document] do |f| %>
        <div class="field"><%= f.file_field :doc %></div>
        <div class="actions"><%= f.submit %></div>
    <% end %>
  </div>
</div>

回答1:

Try with:

<%= form_for([@event, @document]) do |f| %>
  ...
<% end %>

Where @event = Event.find(params[:id]) and @document = Document.new

Refer: http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for

Hope it helps :)