All Projects → werein → X Editable Rails

werein / X Editable Rails

Licence: mit
Edit fields easily with X-Editable helper

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to X Editable Rails

Bh
Bootstrap Helpers for Ruby
Stars: ✭ 834 (+424.53%)
Mutual labels:  rails, bootstrap, bootstrap3
Ladda Bootstrap
Ladda buttons concept originally by @hakimel, example using Bootstrap 3 by @msurguy
Stars: ✭ 1,258 (+691.19%)
Mutual labels:  bootstrap, bootstrap3
Tabler Rubygem
Rubygem for https://tabler.github.io
Stars: ✭ 77 (-51.57%)
Mutual labels:  rails, bootstrap
Aurelia Slickgrid
Aurelia-Slickgrid a wrapper of the lightning fast & customizable SlickGrid datagrid with a few Styling Themes
Stars: ✭ 100 (-37.11%)
Mutual labels:  bootstrap, bootstrap3
Bootstrap Blog Template
An awesome blog template constructed using Twitter Bootstrap 3
Stars: ✭ 29 (-81.76%)
Mutual labels:  bootstrap, bootstrap3
Redmine bootstrap kit
A Redmine plugin which makes developing your own Redmine plugin easy ;)
Stars: ✭ 36 (-77.36%)
Mutual labels:  rails, bootstrap
Bootstrap Colorpicker
Bootstrap Colorpicker is a modular color picker plugin for Bootstrap.
Stars: ✭ 1,351 (+749.69%)
Mutual labels:  bootstrap, bootstrap3
Milog
Milog 是一基于 Ruby on Rails 的个人博客网站
Stars: ✭ 24 (-84.91%)
Mutual labels:  rails, bootstrap
Vue Cli Multipage Bootstrap
vue-cli-multipage-bootstrap demo with vue2+vue-router+vuex+bootstrap+markdown for learning vue2.0
Stars: ✭ 105 (-33.96%)
Mutual labels:  bootstrap, bootstrap3
Bootstrap Validate
A simple Form Validation Library for Bootstrap 3 and Bootstrap 4 not depending on jQuery.
Stars: ✭ 112 (-29.56%)
Mutual labels:  bootstrap, bootstrap3
Wordpress Bootstrap
Bootstrap in WordPress theme form - Bootstrap 3.3.1
Stars: ✭ 1,494 (+839.62%)
Mutual labels:  bootstrap, bootstrap3
Uiv
Bootstrap 3 components implemented by Vue 2.
Stars: ✭ 882 (+454.72%)
Mutual labels:  bootstrap, bootstrap3
Bootstrap
Repository for my tutorial course: Bootstrap 3 Essential Training on LinkedIn Learning and Lynda.com.
Stars: ✭ 14 (-91.19%)
Mutual labels:  bootstrap, bootstrap3
Bootstrap Ui
⚠️ IN MAINTENANCE MODE. Bootstrap UI is a Bootstrap extension for building beautiful web apps user interfaces.
Stars: ✭ 60 (-62.26%)
Mutual labels:  bootstrap, bootstrap3
Bootstrap
Open Source JS plugins
Stars: ✭ 13 (-91.82%)
Mutual labels:  bootstrap, bootstrap3
Instuigram
🎓 Learning Ruby on Rails through building the Instagram Application.
Stars: ✭ 88 (-44.65%)
Mutual labels:  rails, bootstrap
Angular Ui Notification
Angular.js service providing simple notifications using Bootstrap 3 styles with css transitions for animating
Stars: ✭ 549 (+245.28%)
Mutual labels:  bootstrap, bootstrap3
Cakephp3 Bootstrap Helpers
CakePHP 3.x Helpers for Bootstrap 3 and 4.
Stars: ✭ 134 (-15.72%)
Mutual labels:  bootstrap, bootstrap3
Bootstrap 4 Utilities
Bootstrap 4 utility classes in LESS CSS for Bootstrap 3 or any other projects.
Stars: ✭ 105 (-33.96%)
Mutual labels:  bootstrap, bootstrap3
Bootstrap form
Official repository of the bootstrap_form gem, a Rails form builder that makes it super easy to create beautiful-looking forms using Bootstrap 5.
Stars: ✭ 1,532 (+863.52%)
Mutual labels:  rails, bootstrap

X::Editable::Rails

Build Status Code Climate Test coverage Version Dependencies

X-editable for Rails

Live demo

Checkout live demo here

Installation

Add this line to your application's Gemfile:

gem 'x-editable-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install x-editable-rails

Usage

Assets

Choose between the following javascripts:

  • bootstrap-editable
  • bootstrap2-editable
  • jqueryui-editable
  • jquery-editable-poshytip

You'll also need to include editable/rails in your scripts for this to work.

#= require editable/bootstrap-editable
#= require editable/rails

Choose the corresponding stylesheets:

  • bootstrap-editable
  • bootstrap2-editable
  • jqueryui-editable
  • jquery-editable
// as CSS
*= require editable/bootstrap-editable

// or SCSS
@import "editable/bootstrap-editable";

Enable editing with jQuery:

$('.editable').editable()

For custom inputs like the Wysihtml5 editor, add these dependencies:

#= require editable/bootstrap-editable
#= require editable/inputs-ext/wysihtml5
#= require editable/inputs-ext/bootstrap-wysihtml5
#= require editable/inputs-ext/wysihtml5-editable
#= require editable/rails

And related stylesheets:

//= require editable/bootstrap-editable
//= require editable/inputs-ext/bootstrap-wysihtml5
//= require editable/inputs-ext/wysiwyg-color

Making Things Editable

x-editable-rails provides a helper method in your view to make your model values editable. By default, you need to specify the model and property that should be editable. A span element is rendered with data-* attributes used by x-editable.

# the editable object and the attribute to edit
%h1= editable @model, :name

You can customize the tag name and title attribute:

  • tag - span by default.
  • title - The model and attribute name are used to create a capitalized title

The editable helper method automatically adds these data-* attributes used by x-editable.

  • url - Uses the polymorphic_path(model) helper method.
  • source - Only populated if the value is a boolean to convert true or false to "Yes" and "No".
  • value - Uses model.name. If model.name were a boolean value or if a source is specified, the source text would be displayed rather than the raw value. (Presumably the value is an ID and the source would have the text associated with that value.)
  • placeholder - Uses the title value by default
# editable object, what_you_want_update, e: exception - when is xeditable? false or can? :edit, object is false
%h1= editable @model, :name, url: model_path, value: @model.name.upcase

Here are some special features to enhance what's baked into x-editable:

  • type - The type of input is automatically detected. By default, if the value is a boolean, the type is "select" with a built-in source that outputs "Yes" and "No" (unless another source is specified).
  • source - In addition to hashes or arrays of hashes, you can also use an array of strings for a simpler structure if the name and value are the same:
source = [ "Active", "Disabled" ]
editable @model, :enabled, source: source
  • value - This option will override the model.name value
  • classes - This is a custom option for x-editable-rails that will change the editable element's CSS class based on the selected value. Use the source hash structure to map a CSS class name to a value. (This functionality is toggled when the value changes and the "save" event is triggered.)
source  = [ "Active", "Disabled" ]
classes = { "Active" => "label-success", "Disabled" => "label-default" }
editable @model, :enabled, source: source, classes: classes, class: "label"
  • nested - Name of a nested attributes (such as globalize's translations)
  • nid - ID of the nested attribute
%h1= editable @model, :name, nested: :translations, nid: @model.translation.id

# example of nested resource
%h1= editable [picture.gallery, picture], :name, nested: :translations, nid: picture.translation.id

Authorization

Add a helper method to your controllers to indicate if x-editable should be enabled.

def xeditable? object = nil
  true # Or something like current_user.xeditable?
end

You can use CanCan and checks the :edit permission for the model being edited.

def xeditable? object = nil
  can?(:edit, object) ? true : false
end
  • e - Specify a custom (error) message to display if the value isn't editable

"Don't Repeat Yourself" Templates

To make your views cleaner, you can specify all your options for each class and attribute in a YAML configuration file. Attributes where the title or placeholder are not different except maybe capitalized can be left out because they are automatically capitalized when rendered (see above).

This example uses the MailingList class and its attributes. The attribute value can be a string, which is used as the title and placeholder. If you want to specify other options, create a hash of options.

Install configuration file like this: rails g x_editable_rails:install, this step is not necessary

class_options:
  MailingList:
    # Specify placeholder text for each attribute or a Hash of options
    name: Mailing list name
    enabled:
      type: select
      source:
        - Active
        - Disabled
    reply_email:
      type: email
      title: Reply-to email
  User:
    email:
      type: email
    password:
      type: password
    mailing_lists:
      type: select
      # specify a URL to get source via AJAX (see x-editable docs)
      source: <%= ::Rails.application.routes.url_helpers.mailing_lists_source_path %>

Now you can specify your editable fields without options because they will be inherited from your YAML config.

model = MailingList.new

editable model, :name    # type: "text",   title: "Mailing list name"
editable model, :enabled # type: "select", title: "Enabled", source: [ "Active", "Disabled" ]

Examples

Gem also contains demo application with integrated x-editable

cd test/dummy
rake db:migrate
rake db:seed
rails g x_editable_rails:install # optional, it generate config example
rails s

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].