Skip to content

vikonava/ajaxcrud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

twitter.com/vikonava

AjaxCRUD

Gem for Rails that creates a convenient scaffold using Ajax in an unobtrusive way usign jQuery and jQueryUI.

This gem has been tested working on Rails 3.

Requirements

  • jQuery

  • jQuery_ujs

  • jQueryUI (including stylesheet and images)

Setup

Add the gem to your Gemfile then run bundle to install it.

gem 'ajaxcrud'

Install jQuery and jQueryUI(js and css) using assets on Rails 3.1 by adding the next line to app/assets/javascripts/application.js

# app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui

And remember to also add the stylesheet and images included on jQueryUI to the app/assets/stylesheets/ folder.

Usage

Theres only one command to run the generator and create a scaffold, and goes as follows:

rails g ajaxcrud NAME [field:type:boolean field:type:boolean]

Where NAME is the name of the model you are going to create. Additional to that field is the name of the attribute you are going to add and type is the type of field, just as a regular scaffold. The extra boolean in there is to indicate if that attribute is going to be indexed in the search field, it can be true, false or blank being false as default.

For example, if we are going to create a scaffold for Person which will include attributes name, address, website and phone_number being name and website the only attributes that are going to be indexed in the search field, we should run the following command:

rails g ajaxcrud Person name:string:true address:text website:string:true phone_number:string

This will create the Ajax scaffold and additional to that a general stylesheet to give some default color to the index table, an ajaxcrud helper to make index.html.erb more self-explanatory.

Additional Configurations

You can configurate the default table to show more attributes that the one’s indexed, just edit the show.html.erb file.

Helpers

Helpers that are going to be added on index.html.erb are:

  • ajaxcrud_js(name, new_text, info_text) post a javascript required code inside your index file. Where name is the name of your model which in our example is person, new_text would be the text to show in the dialog box when a user is going to be created and also info_text works in a similar way but for the show dialog.

  • ajaxcrud_dialogbox(name) is used to post the code that build the dialog boxes on the file. Where name is the name of your model which in our example is person.

  • ajaxcrud_notices(name) is included in the place where notices will be shown in a flash[:notice] style but with some different finish. Where name is the name of your model which in our example is person.

  • ajaxcrud_search(name) is the search field used to look for in the table records. Where name is the name of your model which in our example is person.

  • ajaxcrud_new_link(name) creates the link to enable the New Record dialog. Where name is the name of your model which in our example is person.

  • ajaxcrud_show_link(path) creates the link to render the show.html.erb file of the selected record inside a dialog. Where path is the original way to access the show file.

Known Bugs

  • When creating the same ajaxcrud twice the migration file is going to be created more than once.

  • If generator destroy is used everything is deleted (including the helper, ajaxcrud.css,…) of the model you indicate EXCEPT the migration file which needs to be removed manually.

  • When destroying a model the ajaxcrud.css and ajaxcrud_helper.rb are also deleted. Since they are being used for all the scaffolds generated you can add them manually and remember to add +include AjaxcrudHelper+ to your app/helpers/application_helper.rb file.

Special Thanks

This gem was made based on some of the tutorial made by ‘Nikunj’ at the {Tech Journey}[http://codefundas.blogspot.com/2010/12/create-ajax-based-curd-using-rails-3.html]‘s website and being adapted to change or add some functionalities to that.

Also thanks to Ryan Bates who helped me find out how to create my first generator and gem, and whose website is awesome and has helped me a lot learning how to code in Ruby on Rails. Highly Recomended.

About

Scaffolding with Ajax and real-time search field

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages