On 4/17/06, Ryan Prins <rprins@gmail.com> wrote:> Hi All,
>
> I have a pretty simple question. I have a view that offers the user the
> following:
>
> A text field to enter in a passphrase
> Another text field to define how many times that phrase is written to the
DB
> It probably doesn''t make sense for it to be written to the DB x
times, but
> this is the first step in a process and the passphrase will become unique.
>
> I currently don''t have a problem saving one phrase to the database
at a
> time, but I am a little unclear on how, at the controller level, to have it
> post to the database x times. I am stumped on how I''d have the
text field
> (#2 above) look in the view and how I''d access it and then
complete a for
> loop over it and save a new row to the table each time until the count is
> reached.
>
> Any ideas on how I''d be able to do this? Thanks in advance!
>
I have no idea why you''d want to do this, but I''ll assume you
can
handle yourself. Heh.
Assuming your view has something like:
<%= text_field ''passphrase'', ''save_count''
%>
In the controller action that posts to, you can say:
count = params[:passphrase][:save_count].to_i rescue 0
count.times do
Passphrase.create params[:passphrase]
end