Best in place inline editing

In some cases, we would like to provide the flexibility to users on editing their content while viewing the content. Best in place is one of the most helpful plugins to provide inline editing feature.

Gems

  • best_in_place

Project Setup

  1. Setup the best_in_place javascript
$(".best_in_place").best_in_place
  1. The controller to save best_in_place update
def update
  @item = Item.find(params[:id])
  if @item.update_attributes(params[:item])
    format.html { redirect_to items_path }
    format.json { head :ok }
  else
    format.html { render :action => "edit" }
    format.json { respond_with_bip(@item) }
  end
end
  1. The best_in_place input can be in several input types eg: text, textarea, select, checkbox
# text
<%= best_in_place @item, :name, :type => :input %>

# textarea
<%= best_in_place @item, :name, :type => :textarea %>

# select dropdown
<%= best_in_place @item, :name, :type => :select, :collection => [[1, "Table"],[2, "Chair"]] %>

# boolean
<%= best_in_place @item, :name, :type => :checkbox, :collection => [true, false] %>

Note: You’ll want to retrieve the actual content from the gists and include them in the code blocks above.