ruby-on-railsrubyruby-on-rails-5best-in-place

rails 5 best in place only updating some <li>s


This is strange. I am using the "best-in-place" gem in combination with an unordered list with each list item including the 'best-in-place' helper. The first item in the list works fine, but subsequent list items have issues. This is the code in my partial (views/_dash.html.erb):

<table class = 'table-hover'>
<li>


    <tr>
        <th class = 'name'> <%= best_in_place offer, :plan_name, :type => :input %> </th>
        <th class = 'name'> <%= best_in_place offer, :price, :type => :input %> </th>
        <th class = 'bids'> Bids(<%= @user.active_bids.count %>) </th>
    </tr>

</li>

And the code in the associated view:

<ul class = "offers">
  <%= render @offers %>
</ul>

<%= will_paginate %>

The first item in the list works fine. Each field displays the right information, is editable, and the edits persist in the db. The second item displays the right fields, is editable, updates the info. However, after a refresh, the fields revert to the original value discounting the edits made. Further items in the list display the right fields initially, but some are not editable, some are editable but do not update the info, some are editable but the edited info does not persist. This is the code for the associated controller:

def update
@user = current_user
@offer = Offer.find params[:id]
if @offer.update_attributes!(offer_params)
  respond_to do |format|
    format.html { redirect_to( @offer )}
    format.json { render :json => @offer }
  end
else
  respond_to do |format|
    format.html { render :action  => :show } # edit.html.erb
    format.json { render :nothing =>  true }
  end
end

def dash
@user = current_user
@offers = current_user.offers.paginate(page: params[:page])
respond_to do |format|
  format.html
  format.json {render :json => @offer}
end

My application.js looks like this:

//= require jquery
//= require jquery.purr
//= require best_in_place
//= require 'rest_in_place'
//= require jquery_ujs
//= require best_in_place.jquery-ui
//= require bootstrap
//= require turbolinks
//= require_tree .

This is my offers.coffee file:

jQuery ->
   $('.best_in_place').best_in_place()

Please let me know if you need more info, if I missed something obvious, or if there is a fix. SOS.


Solution

  • OK, fixed it. It was an issue with one of my before filters. Sorry about that folks.