Ruby 在 Rails 上 React 得到 NoMethodError

Ruby on Rails with React getting NoMethodError

下面是我的控制器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视图html.erb文件。

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

以下是我的react前端

@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

我收到的错误信息是:

Completed 500 Internal Server error in ActiveRecord.

NoMethodError (undefined method ` ' for ProjectsController#show:0x007fa195b59da0

Started GET "/projects/1" for 127.0.0.1 at 2016-11-24 06:31:38 -0800 Processing by ProjectsController#show as HTML Parameters: {"id"=>"1"} User Load (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]] User Load (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) User Load (0.1ms) SELECT "users".* FROM "users" WHERE (id = 1) Completed 500 Internal Server Error in 17ms (ActiveRecord: 0.5ms)

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

Rendered /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) Rendered /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.1ms) Rendered /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) Rendered /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 within rescues/layout (19.6ms) Rendered /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) Rendered /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 within layouts/inlined_string (0.2ms) Rendered /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 within layouts/inlined_string (0.3ms) 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 within layouts/inlined_string (0.4ms) Rendered /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.erb within layouts/javascript (22.3ms) 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 within layouts/javascript (0.2ms) Rendered /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 within layouts/javascript (0.2ms) 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.9ms)

@supervisors 作业的末尾有四个 space。删除尾随白色 space,错误消失。