Skip to content

Instantly share code, notes, and snippets.

@grin
Forked from ascot21/active_admin.js
Created April 14, 2016 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grin/bf1f31b41e2ab1a634623711d3ace4cb to your computer and use it in GitHub Desktop.
Save grin/bf1f31b41e2ab1a634623711d3ace4cb to your computer and use it in GitHub Desktop.
Inline Editing in ActiveAdmin with Best In Place Gem
//= require jquery
//= require best_in_place
//= require jquery.purr
//= require active_admin/base
$(document).ready(function() {
$(".best_in_place").best_in_place()
$('.best_in_place').bind("ajax:success", function () {$(this).closest('tr').effect('highlight'); });
$(document).on('best_in_place:error', function(event, request, error) {
// Display all error messages from server side validation
response = $.parseJSON(request.responseText);
$.each(response['errors'], function(index, value) {
if(value.length > 0) {
if( typeof(value) == "object") {value = index + " " + value.toString(); }
var container = $("<span class='flash-error'></span>").html(value);
container.purr();
};
});
});
});
gem 'best_in_place'
.purr {
position: fixed;
top: 30px;
left: 30px;
width: 250px;
padding: 15px;
background-color: rgba(155,0,0,0.7);
border-radius: 5px;
z-index: 9999;
color: white;
&:first-letter { text-transform: uppercase; }
}
column :position do |i|
best_in_place i, :featured, type: :checkbox, path: [:admin, i]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment