0
I am creating a menu to access part of relay of some system features, but when creating the controller of license_report, when I try to access the path "license_report_path"
He presents me with this mistake Actioncontroller::Routingerror (No route Matches {:action=>"show", :controller=>"license_report"}):
my Routes.Rb this way :
resources :license_report, only: [:index, :show]
My license_report_controller.Rb looks like this:
# encoding: utf-8
class LicenseReportController < ApplicationController
before_filter :require_user
before_filter :set_contractual_instrument, only: [:show]
def index
includes = [:cr_program, :highway]
@contractual_instruments = CrContractualInstrument.includes(includes).order(:ic_number)
@contractual_instruments = @contractual_instruments.select { |ci| ci.valid_inspections.any? }
end
def show
@license = License.where("cr_contractual_instrument_id = #{params[:id]}")
byebug
respond_to do |format|
byebug
format.html do
add_breadcrumb 'Relátorios de licenças', 'license_report_path'
end
format.pdf do
byebug
pdf = LicenseReportPDF.new(@license.map{|license| license.id})
send_data pdf.render, filename: pdf_filename, type: 'application/pdf', disposition: :inline
end
end
end
private
def set_contractual_instrument
@contractual_instrument = CrContractualInstrument.find(params[:id])
end
def pdf_filename
time = Time.current.strftime('%Y-%m-%d-%H%M%S')
name = @contractual_instrument.ic_number.gsub('/', '-')
"#{name}_#{time}.pdf"
end
end
If I withdraw any mention of license_report_path the code returns to work normally.
How do I add this route, it should be included in Resources or I’m thinking wrong?
Thanks!! It worked, but. I wanted him to enter without mandatory parameter and I could not visualize where "I set" this parameter as mandatory.
– Thiago Vaz
the Resources :license_report, only: [:show] that generates this dependency of an ID, to make a show without this dependency, you can use the Resource that will look like this: Resource :license_report, only: [:index, :show] , or more rubocop Resource :license_report, only: %i[index show]
– André Oliveira