That did cross my mind, but I also wanted to know how to do something
like this if it was possible.  attr[:city] didn't work..

But here's what I'm really trying to do.
I have a form that lets user enter transport information like arrival/
departure airports, time, etc.  If there are transits in between, user
can add as many transits as they like - or None.  When the form is
submitted, even when there are no transits, there is one empty
transports_transits_attributes, and I'm trying to catch that somehow
so it doesn't get saved to the database with blanks.

Here's the model:

--------------------------------------------
class Transport < ActiveRecord::Base

  has_many :users, :through => :transports_users
  has_many :transports_transits, :dependent => :destroy
  accepts_nested_attributes_for :transports_transits, :allow_destroy
=> true

end
--------------------------------------------

and the form snippet for where transits are added/removed

--------------------------------------------
<div id="transits" style="display: none">
  <% f.fields_for :transports_transits do |i| %>
    <%= render :partial => 'transport_transit', :locals => { :form =>
i } %>
  <% end %>
</div>
<%= add_transport_transit_link(f) %>
--------------------------------------------

and in the helper, I have
--------------------------------------------
def add_transport_transit_link(form_builder)
  link_to_function 'Add transits' do |page|
    form_builder.fields_for :transports_transits,
TransportsTransit.new, :child_index => 'NEW_RECORD' do |f|
      html = render(:partial => 'transport_transit', :locals =>
{ :form => f })
      page << "if($('transits').visible()) $('transits').insert
({ bottom: '#{escape_javascript(html)}'.replace(/NEW_RECORD/g, new Date
().getTime()) }); else $('transits').show();"
    end
  end
end
--------------------------------------------

As you can see, at first, this div is invisible and only becomes
visible when the add_transport_transit_link is clicked for the first
time by the user.  The subsequent click will actually add more
transport_transit form.

*** So the real problem is that the first transit form is there
(although invisible).***

I couldn't figure out how to not have the first transit initially -
and that's why I was trying to deal with it after the fact.  I hope
I'm making sense here.
--~--~---------~--~----~------------~-------~--~----~
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