Thank you Frederick for clearing that up for me.  So I guess the
problem is in my Views?

Here’s the Javascript to add more fields:
<%= add_object_link 'Add Another Blog', 'tasks', :partial => 'blogs'
%>

‘tasks’ is only the div id
And here’s the helper

  def add_object_link(name, where, render_options)
    html = render(render_options)
    link_to_function name, %{
      Element.insert('#{where}', #{html.to_json}.replace(/
index_to_replace_with_js/g, new Date().getTime()));
    }
  end

and finally the partial
<% @blogs.each do |blog| %>
        <% fields_for "blogs", blog, :index => "index_to_replace_with_js" do |
f| %>
                <%= f.error_messages %>
                        <%= render :partial => "form", :locals => { :f => f } %>
<% end %>
<% end %>
The actual form fields in the partial named “form” are just your
typical f.label and f.text_field entry stuff.

>“How have you confirmed that the extra fields have not been submitted ?”
By submitting the form manually and looking at the logs.  Only the
first one gets added, or however many I set in the Array through the
controller.  None of the Javascript added fields get added, although
their html is formatted correctly.  It’s like it doesn’t even see
them.

So, I removed the fields in the view set by the Array, so there were
no fields and only the “Add Another Blog” link was present.  I then
added 1 form via the javascript and clicked on Submit.  This is the
error I get:
undefined method `values' for nil:NilClass

C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/
whiny_nil.rb:52:in `method_missing'
C:/Rails/AppName/app/controllers/blogs_controller.rb:9:in `create'

So you’re right, the problem isn’t with my controller, but my form.  I
think the Javascript is correct, but I’m doing something funky with
form.  This is the “new” view that sets the number of default fields
according to the number in the Array.
<% form_tag :action => 'create' do %>
        <% @blogs.each_with_index do |blog, index| %>
                <% fields_for "blogs[#{index}]", blog do |f| %>
                                <%= f.error_messages %>
                        <%= render :partial => "form", :locals => { :f => f } %>

Maybe the problem is with the form_tag :action => 'create' do line?
I’m really not sure, but any more insight into this is greatly
thanked.


On Feb 16, 4:05 am, Frederick Cheung <[email protected]>
wrote:
> On Feb 16, 3:32 am, AlwaysCharging <[email protected]> wrote:
>
> > What am I doing wrong?
> > Is it because I’m limiting the array to 1? but allowing the user to
> > add more?  Is there a way to allow Array to accept any and all, but
> > only display 1 by default?
>
> new Array(1) just means create an array initially containing 1 object
> (nil). There aren't ever any restrictions on how many items you can
> stick in an array (besides if the problem is with javascript created
> form elements then problem is happening long after the array stopped
> being relevant. What does the javascript to add the form fields look
> like? How have you confirmed that the extra fields have not been
> submitted ?
>
> Fred

-- 
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.

Reply via email to