On 14 Apr 2011, at 19:30, Andrew Miehs <[email protected]> wrote:
> Hi all, > > I am new to ruby and rails coming from a perl background. > > I was hoping someone could help point me to some sample code to serialize > data from a form. > My plan is to write a tiny app to generate Cisco switch configuration files > based on a template. > > Below is what I have found so far based on what I could find. > > 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? > 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 Fred > Any pointers would be helpful. > > Thanks in advance, > > Regards > > Andrew > > > --- > > === switch.rb === > class Switch < ActiveRecord::Base > serialize :configuration > end > > === _form.html.erb === > <%= form_for(@switch) do |f| %> > <% if @switch.errors.any? %> > <div id="error_explanation"> > <h2><%= pluralize(@switch.errors.count, "error") %> prohibited this > switch from being saved:</h2> > > <ul> > <% @switch.errors.full_messages.each do |msg| %> > <li><%= msg %></li> > <% end %> > </ul> > </div> > <% end %> > > <div class="field"> > <%= f.label :name %><br /> > <%= f.text_field :name %> > </div> > > > <%= f.fields_for :configuration do |c| %> > <%= c.text_field :snmpCommunity %> > <%= c.text_field :ipAddress %> > <% end %> > > > <div class="actions"> > <%= f.submit %> > </div> > <% end %> > > -- > 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. > -- 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.

