首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails上有收集路径的另一种方法的索引中的nomethoderror

Rails上有收集路径的另一种方法的索引中的nomethoderror
EN

Stack Overflow用户
提问于 2017-03-31 15:57:30
回答 2查看 168关注 0票数 0

我想创建一个excel文件。当我尝试继续运行时,professionals/628/medical_records将显示以下消息

代码语言:javascript
复制
undefined method `report_medical_records_path' for #<#<Class:0x0000000d0eb4f8>:0x0000000d0ea080>

对于模板上的下列行,这一行是必须指向创建de文件的路由的链接。

代码语言:javascript
复制
.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

这是我的indexreport动作

代码语言:javascript
复制
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

以及路线:

代码语言:javascript
复制
resources :medical_records, controller: 'medical_records' do
      collection do
        get :report
      end
    end

更新状态

我会把问题提上去,所以仍然是过时的。

当前错误消息:

代码语言:javascript
复制
The action 'report' could not be found for MedicalRecordsController

现在我在航线上看到了这个:

代码语言:javascript
复制
resources :professionals do
    #...
    resources :medical_records, controller: 'medical_records', only: [] do
      collection do
        get :report
      end
    end
  end

action is MedicalRecordsController是这样的:

代码语言:javascript
复制
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

为什么在控制器中找不到动作?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-18 14:26:43

解决了最新的问题!

动作在private内部,然后向上移动。

票数 0
EN

Stack Overflow用户

发布于 2017-04-02 00:40:39

您想要的路由/操作对于rails来说是不标准的。您需要在routes.rb中告诉它更多的信息,以便得到您想要的东西,特别是操作。

代码语言:javascript
复制
resources :medical_records, controller: 'medical_records' do
  collection do
    get :report, action: :report
  end
end

这将为您提供以下路线:

代码语言:javascript
复制
report_medical_records GET  /medical_records/report(.:format)   medical_records#report
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43144960

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档