0

以下是我的控制器 Projects#show 方法。

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

以下是我的 Projects#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 开始 GET "/projects/1" for 127.0.0.1 由 ProjectsController#show 作为 HTML 参数处理:{"id"=>"1"} 用户负载 (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]]
Project Load (0.1ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT 1 [["id", 1]] 用户负载 (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
(0.1ms) SELECT "relationships"."supervisor_id" FROM "relationships" WHERE (supervisor_id = 1) 用户负载 (0.

NoMethodError (undefined method '' for#): app/controllers/projects_controller.rb:11:in `show'

渲染 /home/ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (2.7ms)渲染 /home/ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.1毫秒)渲染/home/ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms)渲染/home/ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html救援/布局中的 .erb (19.6ms) 渲染 /home/ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates /_markup.html.erb (0.2ms) 渲染 /home/ferg/。rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb 在 layouts/inlined_string (0.2ms) 内渲染 /home /ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb 在 layouts/inlined_string (0.3ms ) 在 layouts/ 中渲染 /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 inlined_string (0.4ms) 渲染 /home/ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/console.js。 layouts/javascript (22.3ms) 内的 erb 渲染 /home/ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/ layouts/javascript 中的 main.js.erb (0.2ms)在布局中渲染/home/ferg/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb /javascript (0.2ms) 渲染 /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.9ms)

4

1 回答 1

0

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

于 2016-11-28T17:19:07.160 回答