-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
executable file
·51 lines (38 loc) · 1.72 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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