2015-05-01 20 views
3

發現未定義的方法'合併」 35:Fixnum對象

不要使用<%= f.hidden_field :field, number %>,使用<%= f.hidden_field :field, value: number %>

發行下文

An ActionView::Template::Error occurred in bookings#new: 

undefined method `merge' for 35:Fixnum 
app/views/bookings/_form.html.erb:31:in `block in _app_views_bookings__form_html_erb__2731573742378725623_70113682151640' 

充分利用這個可怕的一般錯誤我們生產網站,目前還不清楚爲什麼。這不會發生在我們的本地主機上。這裏的線上面提到的:

<%= current_employer.locations.first.name_or_address_1 %> 

其中name_or_address_1是:

return "from #{name}" if name.present? 
"from #{address_1}" 

我已經去到控制檯,並運行「name_or_address_1」在我們的數據庫中,正常工作的每個位置,而「locations.first.name_or_address_1 「爲我們數據庫中的每個僱主。再次,工作正常。所以肯定它不可能是這條線?

編輯:我只是註釋掉線,部署到生產,仍然出現錯誤。這是怎麼回事?爲什麼錯誤的行被引用?

這裏的部分:

<%= form_for @employer, url: bookings_path, method: :post, html: { class: "main-form", id: "create-booking" } do |f| -%> 
    <% @employer.errors.full_messages.each do |msg| %> 
    <p><%= msg %></p> 
    <% end %> 

    <div id="bookings"> 
     <ol class="numbers"> 
     <li> 
      <legend>Location, Pay, & Vehicle</legend> 

      <div class="form-group"> 
      <div class="row"> 
       <div class="col-sm-6"> 
       <label>Type of job</label><br> 
       <%= f.select(:job_type_id, options_from_collection_for_select(JobType.all, :id, :name_with_delivery), {}, { id: 'job-type', class: 'form-control' }) %> 
       </div> 
       <div class="col-sm-6"> 
       <label>Vehicle needed</label><br> 
       <%= f.select(:vehicle_id, options_from_collection_for_select(Vehicle.all, :id, :name), {}, { id: 'vehicle-type', class: 'form-control' }) %> 
       </div> 
      </div> 
      </div> 

      <div class="form-group"> 
      <div class="row"> 
       <div class="col-sm-6"> 
       <label>Location</label> 
       <% if current_employer.locations.size > 1 %> 
        <%= f.select :location_id, options_from_collection_for_select(current_employer.locations.all, :id, :name_or_address_1), {}, { class: 'form-control' } %> 
       <% elsif current_employer.locations.size == 1 %> 
        <p><strong>Location: </strong><%#= current_employer.locations.first.name_or_address_1 %></p> 
        <%= f.hidden_field :location_id, current_employer.locations.first.id %> 
       <% end %> 
       <%= link_to "or add new location", new_employer_location_path(current_employer, Location.new) %> 
       </div> 
       <div class="col-sm-6"> 
       <%= f.label :pay %> 
       <span id="length-message" class="pull-right" style="color: #a94442"></span> 
       <br> 
       <%= f.text_field :pay, class: 'form-control', id: 'pay', maxlength: '18' %> 
       </div> 
      </div> 
      </div> 

     </li> 
     <legend>Shifts</legend> 
     <%= render 'booking', booking: Booking.new %> 
     </ol> 
    </div> 

    <%= link_to "Add another shift", "javascript:;", class: 'add-shift', style: 'margin-left: 40px;' %> 

    <script type="text/javascript"> 
    $(".add-shift").click(function(){ 
     $("ol.numbers").append("<%= j render 'booking', booking: Booking.new %>") 
    }); 
    </script> 

    <%= f.submit "Post Shifts", class: 'btn green-button pull-right' %> 
    <br> 
    <br> 
    <br> 
    <span class="error-message bg-danger pull-right"> 
    </span> 
<% end %> 
+0

你能後周圍的行呢?只是爲了給出一個上下文 – MCBama

+0

您使用了合併方法嗎?從錯誤中,似乎你已經在fixnum數據類型上使用了.merge。 – Finks

+1

找到了!不要使用'<%= f.hidden_​​field:field,number%>',使用'<%= f.hidden_​​field:field,value:number%>' –

回答

6

不要使用

<%= f.hidden_field :field, number %> 

使用

<%= f.hidden_field :field, value: number %> 
相關問題