I have the following.
class Page < ActiveRecord::Base
belongs_to :category
serialize :fields
end
The value of fields
will depend on the category. But as an example;
{"address" => "8 finance street, hong kong",
"founded" => "1973"}
In this example the category has defined "address"
and "founded"
as the custom fields.
What I want is to say;
= simple_form_for(@page) do |f|
= f.association :category
- f.object.category.fields.each do |field|
= f.input field.name
But I need to do something magic to deal with the fact that @page.founded
is not valid
Instead I should be looking at @page.fields["founded"]
.
Any suggestions?
Update:
I've got slightly nearer
- if f.object.category
- f.object.category.fields.each do |field|
= f.input field.name do
= text_field_tag "post[fields][#{field.name}]", f.object.fields[file.name]
Now need to make this DRYer (don't want to specify the name of the object).
I'll see if I can write a decent simple form extension for this.