Hello,
I have a generate method that generate PIN codes and serial numbers n times, n comes from a user-submitted form, something like that:
<% form_for :card, :url => {:action => “generate”} do |f| -%>
Number of cards
<%= f.text_field :number_of_cards, :size => 10 %>
<%= submit_tag ‘Generate’ %> <% end -%>
In the controller I have:
def generate
params[:number_of_cards].to_i.times do pin = rand(999999999999).to_s.center(12, rand(9).to_s) serial = rand(999999999999).to_s.center(12, rand(9).to_s) Card.create({:pin => pin, :serial => serial})
end end
Everything looks OK, but when I put a number and submit the form I got nothing! No error messages and no records are saved to the database !!! When I for example put : 3.times do … etc
3 new records are successfully created in the database !
what’s the problem? Maybe params[:number_of_cards] doesn’t get the value from the form? Why? And if so why don’t I get error about some nil value?
Your help is really appreciated.
Regards