This may not be the correct way of doing things, but I'm honestly not sure how else to do it.
I'm creating an import system which will take a serialized string as an input, deserialize it into ActiveRecord objects, and then show the user a confirmation screen that displays all items that will be imported and when the user presses a "save" button, the items are all saved.
I have the deserialization done and I have the confirmation page built so that it shows each item that will be imported.
The last step is a button that when pressed, will save every item.
I thought this was as simple as having something like this in my view:
<%= button_to 'Save Items', :action=> :save_items %>
and this in my controller:
def save_items
@items_to_save.each do |item|
item.save
end
end
(@items_to_save is an array of ActiveRecord objects)
However, because the button_to appears to be actually causing a new request, @items_to_save is lost as soon as the button is pressed.
Is there some better way to tie a button on the view to a controller action so that a new request isn't triggered and my items aren't lost?