jeudi 28 avril 2016

create Form For basic Class not Model

Lets say I have a class that generates a PDF as output. Different attributes can passed to it when initializing it.

 PDFGenerate.new(page: 4, user: 5, year: 2016, day: 13 ....)

Now I would like to create an View/Controller for that Class so that the user can simply create a PDF over the Web Applicaction. I would like to do something like that:

class PDFController < ActionController::Base
    def index
       @pdf_generate = PDFGenerate.new
    end

    def show
       send_data PDFGenerate.new(params).inline
    end
end

In my view I would like to have:

<%= form_for @pdf_generate do |f| %>

<%=  f.text_field :page %>
.......

But it is not working like this because @pdf_generate Is not a Model. How can I create a Form for a Basic Class like PDFGenerate ? Thanks

Aucun commentaire:

Enregistrer un commentaire