Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
ActsAsVirtualAttribute ====================== Acts As Virtual Attribute is a plugin released under the MIT license. It creates virtual attributes on ActiveRecord models using the pattern documented in The Pragmatic Programmers' Advanced Rails Recipes. Thanks to Ryan Bates for all of the swell examples he has created on Railscasts.com. Example ======= class Project < ActiveRecord::Base has_many :tasks, :dependent => :destroy acts_as_virtual_attribute :tasks end <% fields_for_task task do |task_form| -%> <p class="task">Task: <%= task_form.text_field :name %> <%= link_to_remove_task "remove", ".task", task_form %> </p> <% end -%> acts_as_virtual_attribute has created the following: * Project#new_task_attributes=(attributes) - used to set new task variables * Project#existing_task_attributes=(attributes) - used to set existing task variables * Project#save_tasks - used to save tasks because Rails doesn't save child objects on update. * an after_update callback to Project#save_tasks - required because Rails doesn't save child objects on update * ProjectsHelper#fields_for_task(task, &block) - provide the field name for the fields_for in the form * ProjectsHelper#link_to_remove_task(name, container, form, &block) - provides a link to remove the current task ** Notes ** If you are using namespaced models, it is expecting a helper for the name of the class. So if you have a model like: class Art::Picture < ActiveRecord::Base has_many :colors, :class_name => "Art::Color" acts_as_virtual_attribute :colors end then you will need to have a PicturesHelper. Be sure that it is loaded by the controller so you can use it in the view. Copyright (c) 2008 Carl B. Fyffe, released under the MIT license