Hi Fred,
On 14/04/2011, at 11:38 PM, Frederick Cheung wrote:
>> Unfortunately the form does not automagically re-insert the values after
>> they are saved. I noticed other people commenting about the same feature. Is
>> there a better way of doing this?
>>
>
> You might try passing @switch.configuration, :configuration to fields_for.
> Why use serialize though, rather than make those things attributes of the
> switches table?
I do not want to use attributes as there are not only 2 but about 20, and
additional ones may come at a later stage.
I am not quite sure what you mean by the above statement....
Changing
<%= f.fields_for :configuration do |c| %>
to
<%= f.fields_for @switch.configuration, :configuration do |c| %>
gives
undefined method `model_name' for NilClass:Class
Unfortunately I am currently trying to work out how the rails framework fits
together while learning ruby syntax at the same time..
>> How would I create an array of vlans under the variable configuration using
>> the form?
>> I am planning on adding an "add vlan" button which reloads the same form,
>> but I am not sure of the syntax.
>>
> If vlans are a separate table (with an association with switches) then
> accepts_nested_attributed makes this sort of thing pretty easy. I believe
> there's a railcard that covers one way of handling the client side portion of
> adding new form thingies on the fly
I don't actually want to do anything with this data other than running it
through a template. That is why I was looking at the following type structure:
name = mySwitch
configuration =
{snmpCommunity = public},
{ipAddress = 10.0.0.1},
{value1 = x}
{vlan = [ { id = 1, name = Vlan1 }, { id = 2, name = Vlan2 }]}
etc etc...
I don't really want to bother normalising the data as this structure may change
quite often....
I am trying to do this in Rails so that I get a chance to learn a little about
the framework...
Thanks for any comments.
Regards
Andrew
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en.