Undefined method `merge 'for 35: Fixnum

Found

Do not use <%= f.hidden_field :field, number %>

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

The problem is below

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'

      

Getting this terrible common error from our website and it's not clear why. This does not happen on our local hosts. Here's the specified line:

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

      

where name_or_address_1

:

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

      

I went into the console and ran " name_or_address_1

" for each location in our database, which works great, and " locations.first.name_or_address_1

" for each employer in our database. Again, works great. Couldn't it be this line?

Edit: I just commented out the expanded line for production and the error still happens. What's happening? What is the wrong line referring to?

Here's a partial:

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

      

+3


source to share


1 answer


Do not use

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

      



use

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

      

+6


source







All Articles