Skip to content

Instantly share code, notes, and snippets.

//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.
@bernat
bernat / gist:809348
Created February 3, 2011 11:00
helper best in place
module BestInPlace
module BestInPlaceHelpers
def best_in_place(object, field, opts = {})
opts[:type] ||= :input
opts[:collection] ||= []
opts[:nil] ||= "-"
field = field.to_s
value = object.send(field).blank? ? opts[:nil].to_s : object.send(field)
collection = nil
if opts[:type] == :select && !opts[:collection].blank?