1) Let's say I have a model Foo that has_many :bars.
When viewing the active_scaffold Foo list, is there a way to make the
"+ new foo" action button prepare a new foo with pre-built associated
records?
In other words, in a normal controller I could do something like this:
def new
@foo = Foo.new
[:baz, :lol, :omg].each do |desc|
@foo.bars.build(:desc => desc)
end
end
So this way, in a regular form, I could do something like:
form_for @foo do |f|
f.fields_for :bars do |bar|
bar.label bar.object.desc
bar.text_field bar.object.desc
end
end
And this would generate a form with inputs like:
baz: _______
lol: ________
omg: _______
...
So basically, I am looking for a way to dynamically build form inputs
for my view, and am wondering how this might be achieved with active
scaffold.
2) If my previous question can't be answered, then is there simply an
easy way that I can make my "+ new foo" button on the active_scaffold
list page render a custom "new" action (so I can have it do what I
described in #1) ?
I'm either looking for a way that I could make active_scaffold render
a custom new action inline with the list view, or actually just do a
page refresh and bring up the new action.. Either way is fine, but
ideally if I could accomplish what I am looking for with #1, then that
would be super ideal.
...
Actually I have a #3 question too.. Supposing that #1 is possible, is
there a way to tell active scaffold to include a custom variable when
triggering the new action?
For example, lets say I want to have a select on the page next to my
"+ new foo" button..
This select would have options: "lol" and "omg"
So, by clicking "+ new foo", it would do a query string ?item=lol or ?
item=omg, and this way I could have the controller action do
something like:
def new
@foo = Foo.new
descs = case params[:item]
when "lol"
[:lol, :lotcats, :rotflmao]
when "omg"
[:omg, :whoa]
end
descs.each do |desc|
@foo.bars.build(:desc => desc)
end
end
... Hopefully you can see where I am going with this... Is this at
all possible?
-patrick
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.