Code Monkey home page Code Monkey logo

bootstrap-editable-rails's Introduction

Bootstrap Editable Rails

In-place editing with Twitter Bootstrap for Rails 3/4

This gem is based on X-editable (v1.5.1) which is the new version of Bootstrap Editable.

https://github.com/vitalets/x-editable

Demo & Documents

See http://vitalets.github.com/x-editable

Installation

Add this line to your application's Gemfile:

gem 'bootstrap-editable-rails'

And then execute:

$ bundle

Usage

JavaScript & Stylesheet

Write the top of app/assets/javascripts/application.js like this:

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-editable
//= require bootstrap-editable-rails
//= require_tree .

and need to load bootstrap-editable.css at the place where you like.

HTML

Follow the documents of X-editable above.

Additional required attribute is resource.

<a href="#" id="username" data-type="text" data-resource="post" data-name="username" data-url="/posts/1" data-original-title="Enter username">superuser</a>

then, sends PUT /posts/1 request with the body:

post[username]=superuser

When using textarea type, textarea_format helper method for formatting line breaks is available.

<a href="#" id="body" data-type="textarea" data-resource="post" data-name="body" data-url="/posts/1" data-original-title="Enter body">
  <%= textarea_format(@post.body) %>
</a>

Controller

PostsController receives the parameters

{ "id" => "1", "post" => { "username" => "superuser" } }

and must respond with 2xx (means success) status code if successful.

For example, scaffold works well by 204 because default dataType is json.

def update
  @post = Post.find(params[:id])

  respond_to do |format|
    if @post.update_attributes(params[:post])
      format.html { redirect_to @post, notice: 'Post was successfully updated.' }
      format.json { head :no_content } # 204 No Content
    else
      format.html { render action: "edit" }
      format.json { render json: @post.errors, status: :unprocessable_entity }
    end
  end
end

Note

The scaffold above will not work with jQuery 1.9.0 (included in jquery-rails 2.2.0) because of jQuery's bug.

jquery/jquery#1142

If you use the old version of jQuery, please update jquery-rails to avoid it.

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

bootstrap-editable-rails's People

Contributors

tkawa avatar deandeblock avatar mthomps avatar zzip avatar gavinhughes avatar

Watchers

James Cloos avatar Vlad Demidov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.