仅在生产中通过补丁方法更新时的form_for模板错误

时间:2014-11-15 23:16:20

标签: ruby-on-rails ruby ruby-on-rails-4 heroku

我有一个包含多个has_many关系的帐户模型。我的表单对这些嵌套资源上的所有CRUD操作使用build方法。一切都在当地工作;但是,当我部署到Heroku并尝试编辑任何资源(包括父帐户资源)时,我收到有关语法的模板错误。我正在使用rails -v 4.0.3,ruby -v 2.0.0p247和Heroku上的Cedar堆栈。这是我的表格:

<div class="container">
  <div class="row">
    <div class="col-md-8 col-md-offset-2 well well-lg">
      <div class="well well-lg" style="background: #fafafa;">
        <h1 class="form-header">Pets</h1>
      </div>
      <%= form_for ([@account, @account.pets.build]), url: account_pet_path(@pet.account_id, @pet.id), method: :patch do |f| %>
        <div class="well well-lg" style="background: #fafafa;">
          <%= f.label  :Name %><br>
          <%= f.text_field :name, :value => @pet.name  %><br>
          <%= f.label :Type %><br>
          <%= f.select :kind, options_for_select(['dog', 'cat', 'rabbit', 'fish', 'bird', 'hamster', 'gerbil', 'guineau pig', 'other']) %><br>
          <%= f.label "Breed or kind" %><br>
          <%= f.text_field :breed, :value => @pet.breed %>
        </div>
        <div class="well well-lg" style="background: #fafafa;">
          <%= f.label :Age %><br>
          <%= f.text_field :age, :value => @pet.age %><br>
          <%= f.label "Birth month" %><br>
          <%= f.text_field :birth_month, :value => @pet.birth_month %>
        </div>
        <div class="well well-lg" style="background: #fafafa;">
          <%= f.label "Health history" %><br>
          <%= f.text_area :health_history, :value => @pet.health_history %><br>
          <%= f.label "Current health" %><br>
          <%= f.text_area :current_health, :value => @pet.current_health %>
        </div>
        <div class="well well-lg" style="background: #fafafa;">
          <%= f.label :Medications %><br>
          <%= f.text_area :med_name, :value => @pet.med_name %><br>
          <%= f.label "Medication procedure" %><br>
          <%= f.text_area :med_administer, :value => @pet.med_administer %><br>
          <%= f.label "Medication doses" %><br>
          <%= f.text_area :med_dose, :value => @pet.med_dose %><br>
          <%= f.text_area :med_frequency, :value => @pet.med_frequency %>
        </div>
        <div class="well well-lg" style="background: #fafafa;">
          <%= f.label :Behavior %><br>
          <%= f.text_area :behavior, :value => @pet.behavior %>
        </div>
        <p>
          <%= f.submit :value => 'Update pet', :class => 'btn btn-primary' %>
          <%= link_to 'Back', account_dashboard_path(@pet.account_id), :class => 'btn btn-primary' %>
        </p>
      <% end %>
    </div>
  </div>
</div>

以下是我在Heroku日志文件中遇到的错误:

ActionView :: Template :: Error(/app/app/views/pets/edit.html.erb:8:语法错误,意外的keyword_do,期待keyword_end

... id,@ pet.id),方法:: patch do | f | @ output_buffer.safe_appe ...

/app/app/views/pets/edit.html.erb:50:语法错误,意外的keyword_ensure,期待输入结束):

5:         <h1 class="form-header">Pets</h1>
6:       </div>
7:
8:       <%= form_for ([@account, @account.pets.build]), url: account_pet_path(@pet.account_id, @pet.id), method: :patch do |f| %>
9:         <div class="well well-lg" style="background: #fafafa;">
10:           <%= f.label  :Name %><br>
11:           <%= f.text_field :name, :value => @pet.name  %><br>

它不喜欢do,它抱怨在我的代码的最后一行(erb:50语法错误)中期待keyword_end。但是肯定有<% end %>来关闭do。我错过了一些明显的东西吗Heroku和我配置这种方式有什么奇怪之处吗?任何帮助将非常感激。

1 个答案:

答案 0 :(得分:0)

您在时间之前已经关闭了括号。正确的语法应该是:

<%= form_for ([@account, @account.pets.build], url: account_pet_path(@pet.account_id, @pet.id), method: :patch) do |f| %>

但是你也可以改进它,因为你已经创造了一只宠物。无需在表单中创建一个:

    <%= form_for ([@account, @pet], url: account_pet_path(@pet.account_id, @pet.id), method: :patch) do |f| %>