Hi Guys! Does anyone have an idea on how to update fields in different tables using a single form? Say i have 3 tables and i wanted to create new entries and update them from a single form. how can i build such a model? diffent textboxes in the form should create new entries in the various table with only a single create button click on one form. Thanks Tanzanite -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-09 02:43 UTC
Re: updating mutiple tables from the same form
You have to use the fields_for tag for this, in the following code I
have two models. One for account and the other is for BillingProfile.
This code uses Rails 1.2.2.
<%= error_messages_for :account %>
<% form_for :account, @a, :url => account_path(@account), :html =>
{ :method => :put } do |f| %>
<fieldset>
<legend>Account Information </legend>
<p>
<label for="package">Package:</label>
<%= f.select :package, Account::PACKAGE_TYPES, :prompt => "Select
a package" %>
</p>
<p>
<label for="db_limit">Upgrade Database:</label>
<%= f.select :db_limit, Account::DATABASE_LIMITS, :prompt =>
"Select database limit" %>
</p>
</fieldset>
<fieldset>
<legend>Billing Information</legend>
<% fields_for :billing_profiles do |billing_profile| %>
<p>
<b>Name</b><br />
<%= billing_profile.text_field :name %>
</p>
<p>
<b>Email</b><br />
<%= billing_profile.text_field :email %>
</p>
<p>
<b>Business phone</b><br />
<%= billing_profile.text_field :business_phone %>
</p>
<p>
<b>Home phone</b><br />
<%= billing_profile.text_field :home_phone %>
</p>
<p>
<b>Company</b><br />
<%= billing_profile.text_field :company %>
</p>
<p>
<b>Address1</b><br />
<%= billing_profile.text_field :address1 %>
</p>
<p>
<b>Address2</b><br />
<%= billing_profile.text_field :address2 %>
</p>
<p>
<b>City</b><br />
<%= billing_profile.text_field :city %>
</p>
<p>
<b>State</b><br />
<%= billing_profile.text_field :state %>
</p>
<p>
<b>Zip</b><br />
<%= billing_profile.text_field :zip %>
</p>
<p>
<b>Country</b><br />
<%= billing_profile.country_select :country, ["United States"]
%>
</p>
<% end %>
</fieldset>
<p>
<%= submit_tag "Upgrade My Account" %>
</p>
<% end %>
On Mar 8, 8:33 pm, Tanzanite Tanzanite <rails-mailing-l...@andreas-
s.net> wrote:> Hi Guys!
>
> Does anyone have an idea on how to update fields in different tables
> using a single form?
>
> Say i have 3 tables and i wanted to create new entries and update them
> from a single form. how can i build such a model?
>
> diffent textboxes in the form should create new entries in the various
> table with only a single create button click on one form.
>
> Thanks
>
> Tanzanite
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks! I will try it and see how it works out. tz -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---