Create a form and PDF's without database

Hello, I am looking for help with a particular problem. I created a site for my company and operators must be able to perform maintenance tasks on devices. After having checked all the tasks, when validating the form, I want to create a PDF but not enter the information in my database (eventually, too much information to store). While browsing the web, I manage to create my view for the form without access to my database, when validating my controller opens the PDF that I ask him, but I cannot send the information entered by the user. I have been researching for several days, but I cannot find what I am looking for. I specify, I have no specific training, I self-train on the net so I must have (I) gaps in ROR. I’m not asking anyone to do my job, but a little bit of sample code allows me to better understand what I’m doing.

thank you in advance

You might want to look into using ActiveModel for this. Adding ActiveModel::Model to a “PORO” model lets you access all the goodies of validation, integration with the rest of Rails, etc. such that you can do everything but persist the data in a database.

Another thing to think about is that you can have a controller without a “matching” model. I have built controllers that don’t relate to any model at all before, there’s no requirement that a FoosController wire up to a Foo model. But it’s not the Rails way to do validation in a controller, so I am thinking that having a database-free model would allow you to organize your validations and any data translation you need, as well as provide you a clear place to hook in your PDF output code.

Here’s an example of what I mean by this, ripped from a working project that accepts search requests and passes them off to an external search service:

class Result
  include ActiveModel::Model

  ATTRS = %i[metatags result_number search_result_snippet title url].freeze

  attr_accessor(*ATTRS)

  def initialize(gsa_result_array)
    ATTRS.each do |name|
      instance_variable_set "@#{name}", gsa_result_array.dig(name)
    end
  end
end

Hope this helps,

Walter