Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `merge' for 35:Fixnum

Found it

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

Issue 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 horrible general error from our production website, and it's not clear why. It's not happening on our local hosts. Here's the line referenced above:

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

where name_or_address_1 is:

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

I've gone into the console and run "name_or_address_1" for every location in our database, which works fine, and "locations.first.name_or_address_1" for every employer in our database. Again, works fine. So surely it can't be this line?

Edit: I just commented out the line, deployed to production, and the error still occurs. What's going on? Why is the wrong line being referenced?

Here's the 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 %>
like image 978
Will Taylor Avatar asked Dec 25 '22 19:12

Will Taylor


1 Answers

Don't use

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

use

<%= f.hidden_field :field, value: number %>
like image 181
Will Taylor Avatar answered Dec 27 '22 10:12

Will Taylor