Я пытаюсь сгенерировать документ Docx, используя Gem Caracal, все было в порядке. Он генерировал файл с некоторым текстом, но теперь я хочу создать с моей датой.
contratos_controller.rb
class ContratosController < ApplicationController
before_action :authenticate_user!
before_action :set_contrato, only: [:show, :edit, :update, :destroy, :export]
access all: [:show, :index], user: {except: [:destroy, :new, :create, :update, :edit]}, site_admin: :all
require './lib/generate_pdf'
# GET /contratos
# GET /contratos.json
def index
@contratos = Contrato.all
end
# GET /contratos/1
# GET /contratos/1.json
def show
end
# GET /contratos/new
def new
@contrato = Contrato.new
end
# GET /contratos/1/edit
def edit
end
# POST /contratos
# POST /contratos.json
def create
@contrato = Contrato.new(contrato_params)
respond_to do |format|
if @contrato.save
format.html { redirect_to @contrato, notice: 'Contrato criado com sucesso' }
format.json { render :show, status: :created, location: @contrato }
else
format.html { render :new }
format.json { render json: @contrato.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /contratos/1
# PATCH/PUT /contratos/1.json
def update
respond_to do |format|
if @contrato.update(contrato_params)
format.html { redirect_to @contrato, notice: 'Contrato atualizado com sucesso' }
format.json { render :show, status: :ok, location: @contrato }
else
format.html { render :edit }
format.json { render json: @contrato.errors, status: :unprocessable_entity }
end
end
end
# DELETE /contratos/1
# DELETE /contratos/1.json
def destroy
@contrato.destroy
respond_to do |format|
format.html { redirect_to contratos_url, notice: 'Contrato excluido.' }
format.json { head :no_content }
end
end
def export
GeneratePdf::contrato(@contrato.day, @contrato.daytwo, @contrato.month, @contrato.year, @contrato.pub, @contrato.razao, @contrato.estado, @contrato.cidade, @contrato.bairro, @contrato.endereco, @contrato.cep, @contrato.cnpj, @contrato.estadual, @contrato.municipal, @contrato.telefone, @contrato.email, @contrato.responsavel, @contrato.estadotwo, @contrato.cidadetwo, @contrato.bairrotwo, @contrato.enderecotwo, @contrato.cpf, @contrato.rg, @contrato.emailtwo, @contrato.art)
redirect_to '/contrato.pdf'
end
def page
contrato = Contrato.find([:day])
Caracal::Document.save(Rails.root.join("public", "example.docx")) do |docx|
docx.style do
id 'Body'
name 'Body'
font 'Times New Roman'
size 24
end
docx.h2 'Personal Data'
docx.p do
style 'Body'
text 'Some text '
text contrato.day
text ''
#text contrato.daytwo
end
docx.p
end
path = File.join(Rails.root, "public")
send_file(File.join(path, "example.docx"))
end
private
# Use callbacks to share common setup or constraints between actions.
def set_contrato
@contratos = Contrato.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def contrato_params
params.require(:contrato).permit(:day, :daytwo, :month, :year, :razao, :estado, :cidade, :bairro, :endereco, :cep, :cnpj, :estadual, :municipal, :telefone, :email, :responsavel, :estadotwo, :cidadetwo, :bairrotwo, :enderecotwo, :cpf, :rg, :emailtwo, :toll, :chemist, :mechanic, :mechanictwo, :mechanicthree, :pub, :pubtwo, :pubthree, :pubfour, :gas, :gastwo, :parking, :theather, :other, art:[])
end
end
Я думаю, что я неправильно установил какой-то параметр, потому что файл работал, пока я не попытался сопоставить свои настройки. Я попытался изменить страницу def, но ничего не работает.