我想创建一个excel文件。当我尝试继续professionals/628/medical_records
时,会显示以下消息
undefined method `report_medical_records_path' for #<#<Class:0x0000000d0eb4f8>:0x0000000d0ea080>
对于模板上的以下行,此行是必须转到创建de excel文件的路径的链接。
.clearfix
div.excel-export
= link_to report_medical_records_path(format: 'xlsx'), id: 'report_medical_records_link', data: { original_href: report_medical_records_path(format: 'xlsx') } do
i.fa.fa-file-excel-o style="margin-right:5px"
span exportar historias
我的index
和report
行动
def index
@medical_records = MedicalRecord.for_organization(current_organization)
medical_records_scope = @medical_records.joins(:owner,:target_user).preload(:owner,:target_user)
medical_records_scope = medical_records_scope.like_with_target_user(params[:filter].strip) if params[:filter]
@medical_records_list = smart_listing_create(:medical_records,
medical_records_scope,
sort_attributes: [[:name, "name"],[:profesional, "users.name"],[:target, "target_users_medical_records.name"]],
partial: 'medical_records/listing'
)
@medical_id = current_user.medical_id
if params[:no_layout]=='true'
render 'index', layout: false
else
render 'index'
end
end
def report
medical_records_scope = begin_of_association_chain.order('active DESC')
medical_records_scope = medical_records_scope.like(params[:filter].strip) if params[:filter]
@medical_records_report = medical_records_scope
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="medical_records.xlsx"'
render disposition: 'inline'
}
end
end
路线:
resources :medical_records, controller: 'medical_records' do
collection do
get :report
end
end
我会先保持质疑,因此仍然过时。
当前错误消息:
The action 'report' could not be found for MedicalRecordsController
现在我在路线中有这个:
resources :professionals do
#...
resources :medical_records, controller: 'medical_records', only: [] do
collection do
get :report
end
end
end
而action
内的MedicalRecordsController
就是:
def report
medical_records_scope = begin_of_association_chain.order('active DESC')
medical_records_scope = medical_records_scope.like(params[:filter].strip) if params[:filter]
@medical_records_report = medical_records_scope
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="medical_records.xlsx"'
render disposition: 'inline'
}
end
end
为什么在控制器中找不到动作?
答案 0 :(得分:1)
您想要的路线/操作不是rails的标准。您需要在routes.rb中告诉它更多信息以获得您想要的信息,特别是动作:
resources :medical_records, controller: 'medical_records' do
collection do
get :report, action: :report
end
end
这将使您获得以下路线:
report_medical_records GET /medical_records/report(.:format) medical_records#report
答案 1 :(得分:0)
行动在private
内,然后向上移动。