Forum: Ruby on Rails Loop to insert into database

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Seth Buntin (Guest)
on 2006-06-14 15:22
I have a form that will display a brief description of a topic and
provide links (1 to many) for that topic.  So I currently have two
tables Articles and Links.  I also some stuff on the form that will add
links to the form so that you can create as many was you would like.
The problem I am having is finding out how to submit each link to the
databasen and aligning those links to the articles.

What do you recommend?
Seth Buntin (Guest)
on 2006-06-14 15:33
Seth Buntin wrote:
> I have a form that will display a brief description of a topic and
> provide links (1 to many) for that topic.  So I currently have two
> tables Articles and Links.  I also some stuff on the form that will add
> links to the form so that you can create as many was you would like.
> The problem I am having is finding out how to submit each link to the
> databasen and aligning those links to the articles.
>
> What do you recommend?

After reading that even I was confused and I wrote it.

I have a form that is taken these fields:

in_your_classroom:
    title
    description
    publish_date

in_your_classroom_links
    title
    url
    description

Each IYC feature can have 1 to many links.  I have a link that will add
a new set of form fields for an extra link.  currently I have each form
field set like this:

<%= text_field "in_your_classroom", "title[]" %>
<%= text_field "in_your_classroom", "url[]" %>
<%= text_area "in_your_classroom", "description[]" %>

I want to loop through each link and add them to my database.  What is
the general practice when doing this?

Thanks.

Seth
This topic is locked and can not be replied to.