0

I'm rendering a partial and rendering it without a layout

format.html { render :layout => false }

All values are displayed correctly, and are editable with best_in_place as expected. However, nil values are showing empty and thus cannot be edited (i.e. no "-" is shown). Trying to specifically use the :nil option doesn't make a difference.

While rendering a layout it shows correctly, however I must not use the layout. Any suggestions?

Example code: Controller

def index
....
@user = User.find(params[:user_id])
  respond_to do |format|
    format.html { render :layout => false } 
    format.json { render json: @user }
  end
end

View

<td class='centered-cell span2'><%= best_in_place @user, :nick_name, :inner_class => 'span1' %></td>
user2339344
  • 951
  • 2
  • 12
  • 22
  • 1
    Please paste some code. – Rails Guy Sep 11 '13 at 07:35
  • not clear...what ` nil values are showing empty and thus cannot be edited (i.e. no "-" is shown)` ?? – Rajarshi Das Sep 11 '13 at 08:25
  • Yes exactly, when the value of the attribute is nil, instead of a '-' that is usally shown, there is an empty-string, and that can't be edited. – user2339344 Sep 11 '13 at 10:58
  • I've found also other people facing same issue, as in this unresolved issue: http://stackoverflow.com/questions/18725948/best-in-place-nil-function-does-not-work-in-ajax-inserted-partial – user2339344 Sep 11 '13 at 11:06
  • OK, I believe to found the answer to this - the nil display is done in the JavaScript section, invoked by the call to $('.best_in_place').best_in_place(). Since this code in my page was called only in the 'ready' JS, it was not called when I've loaded a partial date, thus best_in_place() was not invoked. Calling best_in_place after the AJAX call have solved this. Thank you – user2339344 Sep 11 '13 at 15:31

1 Answers1

0

in my case it was that i used type: :select but collection: was empty

so i had to do something like this to catch it for empty selectbox

<%= best_in_place [:admin, resource], :select_attr, type: :select, collection: SelectModel.all.map{|sm| [sm.id, sm.name]}.presence||[nil, 'nil'] %>
okliv
  • 3,909
  • 30
  • 47