Prev | Current Page 343 | Next

David Berube

"Practical Reporting with Ruby and Rails"

upto(number_of_elements_displayed) do |i|%>

<%=text_field "trainee", 'name',:index=>i %>
<%=text_field "trainee", 'employer', :index=>i %>
<%=text_field "trainee", 'grade', :index=>i, :size=>3, :value=>'0'%>%

<%end%>
<%=submit_tag 'Upload', :class=>'submit_button'%>

<%end%>
Note the :index option passed to each text_field element. This lets you submit multiple
objects with the same name, and Rails turns them into an array before passing them
to your controller.
Let??™s examine the controller part of this action next (in Listing 12-4):
CHAPTER 12 n CREATING REPORTS WITH RUBY AND MICROSOFT OFFICE 248
def upload
if request.post?
count = 0
training_class = TrainingClass.find_by_id(params[:training_class_id])
training_class_date = Date.parse(params[:training_class_date])
First, this code checks if the form has been submitted yet by checking the
request.post? flag. If the request.post? flag is set, then the request is an HTTP POST
request, which means that the user has submitted the form.


Pages:
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
wyciągarki wróżby miłosne cukiernia-stykowscy.pl salon kosmetyczny kraków pompy ciepła