当前位置: 首页 > 知识库问答 >
问题:

ruby on Rails with React getting NoMethodError

霍弘厚
2023-03-14

以下是我的控制器项目#显示方法。

def show
    @project = Project.find(params[:id])
    @pm = User.find(@project.user_id)
    @employees = {}
    @supervisors = User.all.where("id = ?", Relationship.all.where("supervisor_id = ?", @project.user_id).pluck(:supervisor_id))    
    @supervisor_ids = Relationship.all.where("supervisor_id = ?",   @project.user_id).pluck(:supervisor_id)
    for supervisor in @supervisor_ids
        @employees[supervisor] = User.all.where("id = ?", Relationship.all.where("supervisor_id = ?", supervisor).pluck(:employee_id))
    end
end

以下是我的项目#show view html.erb文件

<%= react_component 'ProjectManage', { pm: @pm, supervisors: @supervisors, employees: @employees } %>

以下是我的反应前端

@ProjectManage = React.createClass
    getInitialState: ->
      pm: @props.pm

    render: ->
      React.DOM.div
        className: 'org-chart'
        @props.pm.email
      for supervisor in @props.supervisors
        React.DOM.ul supervisor.email
        for employee in @props.employees[supervisor]
          React.DOM.li employee.email

我得到的错误消息是:

ActiveRecord中已完成500内部服务器错误。

NoMethodError(ProjectsController#show:0x007fa195b59da0的未定义方法“”

在 2016-11-24 06:31:38 -0800 开始为 127.0.0.1 获取 “/projects/1” 由 ProjectsController#show as HTML 参数处理: {“id”=

NoMethodError(未定义方法'

Rendered /home/ferg/。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/action pack-4 . 2 . 6/lib/action _ dispatch/middleware/templates/rescues/_ source . erb(2.7 ms)Rendered/home/ferg/。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/action pack-4 . 2 . 6/lib/action _ dispatch/middleware/templates/rescues/_ trace . html . erb(1.1 ms)Rendered/home/ferg/。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/action pack-4 . 2 . 6/lib/action _ dispatch/middleware/templates/rescues/_ request _ and _ response . html . erb(2.0 ms)Rendered/home/ferg/。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/action pack-4 . 2 . 6/lib/action _ dispatch/middleware/templates/rescues/diagnostics . html . erb在rescues/layout(19.6 ms)Rendered/home/ferg/内。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/we b-console-2 . 3 . 0/lib/web _ console/templates/_ markup . html . erb(0.2 ms)Rendered/home/ferg/。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/we b-console-2 . 3 . 0/lib/web _ console/templates/_ inner _ console _ markup . html . erb在layouts/inlined _ string(0.2 ms)Rendered/home/ferg/内。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/we b-console-2 . 3 . 0/lib/web _ console/templates/_ prompt _ box _ markup . html . erb在layouts/inlined _ string(0.3 ms)Rendered/home/ferg/内。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/web-console-2 . 3 . 0/lib/web _ console/templates/style . CSS . erb在layouts/inlined _ string(0.4 ms)Rendered/home/ferg/内。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/we b-console-2 . 3 . 0/lib/web _ console/templates/console . js . erb在layouts/JavaScript(22.3 ms)Rendered/home/ferg/内。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/web-console-2 . 3 . 0/lib/web _ console/templates/main . js . erb在layouts/JavaScript(0.2 ms)Rendered/home/ferg/内。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/we b-console-2 . 3 . 0/lib/web _ console/templates/error _ page . js . erb在layouts/JavaScript(0.2 ms)Rendered/home/ferg/内。rbenv/versions/2 . 3 . 1/lib/ruby/gems/2 . 3 . 0/gems/web-console-2 . 3 . 0/lib/web _ console/templates/index . html . erb(34.9毫秒)

共有1个答案

牛枫
2023-03-14

@supervisors作业结束时有四个空间。删除了尾随空格,错误消失了。

 类似资料:

相关问答

相关文章

相关阅读