Datalist For plugin
Plugin details
Documentation
ruby script/plugin install http://luckymonk.com/svn/repos/datalist_for/
After installing the plugin, just include DatalistFor in your controller, and drop the datalist\_for tag into your form. So, your complete form might look like:
<%= form_tag "save" %> <%= datalist_for :monkeys, Monkey.find(:all) %> <%= submit_tag "Save" %> <%= end_form_tag %>
This will spit out a fully editable page of your favorite pet monkeys (and who doesn’t have pet monkeys). Then, in the target action of your form, do a save\_datalist to save the data. An example:
def save save_datalist flash[:notice] = "Your monkeys have been saved." redirect_to :action => 'whatever' end
You can also specify a subset of your model data:
<%= datalist_for :monkeys, Monkey.find_all_by_user_id(1), :create_with => { :user_id => 1 } %>
This will give you only monkeys for User 1. And any new monkeys will belong to User 1.
Other options:
<%= datalist_for :monkeys, Monkey.find_all_by_user_id(1), { :create_with => { :user_id => 1 }, :show_header => false, :add_text => "Add a new monkey", :exclude => [:likes_bananas, nickname], :delete_content => image_tag "trash" } %>
This means:
* Don’t show the header row
* Use “Add a new monkey” as the link text for adding a new record (defaults to “Add modelname“)
* Exclude the :likes_bananas and :nickname columns
* Will use “trash.png” for row deletion instead of the default “Delete” text
Demo Here's the obligatory demo page. Installation Installing is straightforward:
ruby script\plugin install http://luckymonk.com/svn/repos/datalist_for
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | (0 older versions) | Last edited by: hardway, 7 months ago

