GithubHelp home page GithubHelp logo

bitcababy / jeditable-rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from afeld/jeditable-rails

0.0 2.0 0.0 183 KB

a gem to add in-place-editable fields to your Rails project

License: MIT License

jeditable-rails's Introduction

jeditable-rails Build Status

A gem to add in-place-editable fields to your Rails project. It is a wrapper for the Jeditable jQuery plugin, so most options for $.editable() can be passed through the options parameter of the helpers.

Requirements

Usage

Assuming a Rails 3 project, in your Gemfile, add:

gem 'jeditable-rails'

Suppose you have a User model with a #zip_code attribute.

<%# app/views/users/show.html.erb %>
<h1>View/Edit your profile</h1>
...
<b>Zip Code:</b>
<%= editable_field @user, :zip_code %>

The helpers can be used in any view you like. The field appears as normal text to the user, but when clicked, turns into a form field that will then be submitted back to the server. By default, jeditable-rails requires an update action when a PUT is done to url_for(object), which is generated by default for Rails scaffolds.

Jeditable also requires the server to respond with the new value. For a simple update action, the code will look something like this:

# app/controllers/users_controller.rb
def update
  # update your model
  @user = User.find(params[:id])
  @user.update_attributes!(params[:user])

  format.html {
    if request.xhr?
      # *** repond with the new value ***
      render :text => params[:user].values.first
    else
      redirect_to(@user, :notice => 'User was successfully updated.')
    end
  }
end

Copyright

Copyright (c) 2011 Aidan Feldman. See LICENSE.txt for further details.

jeditable-rails's People

Contributors

afeld avatar all4miller avatar

Watchers

 avatar  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.