ruby on rails - generate pdf if object is persisted -


i'm using wicked_pdf gem generate pdf file:

i want generate pdf if object persisted/saved in database:

something this:

def new   @invoice = invoice.new   respond_to |format|     format.html # new.html.erb   end end  def create   @invoice = invoice.new(invoice_params)   respond_to |format|     if @invoice.save       format.html { redirect_to invoice_path(@invoice), notice: "yesss!") }     else       format.html { render action: new, :alert => "oops :(" }     end     format.pdf       @example_text = "exampletext"         render :pdf => "file_name",                :template => 'path/to/template'     end   end end 

but code respond html. want generate pdf inside of:

if @invoice.save   #generate pdf here   format.html { redirect_to invoice_path(@invoice), notice: "yesss!") } else 

how can it, can use callback?

remove respond_to block so:

def create ...   if @invoice.save    render :pdf=>"file_name",    :template=>'/path/to/template'   else     render action: "new", :alert=>"oops :("   end  end 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -