Devise中的NoMethodError :: SessionsController#在使用“after_sign_in_path_for(resource)”时创建

我正在尝试为我的测验webapp编写function,允许重新连接的用户继续他们中断的地方(重新连接的可能原因是:因为他们丢失了连接,或者因为他们无意中注销,或者因为他们刷新了页面)。

所以我用Google搜索并找到了解决方案,我可以在"after_sign_in_path_for(resource)"编写方法"after_sign_in_path_for(resource)" ,并且在用户登录后,我在该方法中放置的任何内容都将由Devise执行。


当我尝试渲染静态页面(甚至是许多静态页面中的一个,取决于我保存到我的数据库的“阶段”参数)时,此解决方案非常有效。 但我的应用程序有2种用户:

  • 单击从静态页面到静态页面的链接的“教师”
  • “学生”,无法控制,但只要教师点击(推送=通过ActionCable收到HTML并替换当前页面),就会推送新的HTML

那么现在学生登录时会发生什么:

  1. after_sign_in_path_for(resource) :确定用户是学生并进行呼叫
  2. 我的quiz_session模型中的find_current_page方法:它检查我的数据库中的phase变量,并调用我的频道服务器端的多个方法之一,例如
  3. 我的IndividualUpdateChannel resend_question_page类方法:此方法构建html并将其广播给Student。

但是:代替接收和显示发送的HTML,学生得到“Devise中的NoMethodError :: SessionsController #create – 未定义的方法`student_url’for#”在日志中它看起来像1.,2。和3.运行,但然后突然应用程序尝试将学生重定向到某个地方? 并失败。

这是控制台输出: https : //pastebin.com/FKmHF4qS

 ... [ActionCable] Broadcasting to student_#3: {:phase=>1, :answers=>["
The call returns immediately without
waiting for the I/O to complete.
", {"ids"=>[9, 10, 11, 12], "current_question_index"=>1}]} Redirected to Completed 500 Internal Server Error in 442ms (ActiveRecord: 103.6ms)

这是完整的错误消息: Devise中的NoMethodError :: SessionsController #create browser screenshot 这是其余的跟踪: https : //pastebin.com/psdyR2w2

以下是执行停止的代码:

 #app\channels\individual_update_channel.rb: class IndividualUpdateChannel < ApplicationCable::Channel ... def self.resend_question_page(student) quiz_session = student.quiz_session new_answer_html = AnswerButtonCreation.new(quiz_session).create #This is where it stops ActionCable.server.broadcast("student_##{student.id}", phase: 1, answers: new_answer_html) end 

我正在使用Rails 5.0.2和Ruby 2.3.3和Devise 4.2.1。 这是我的第一个Rails项目,所以请原谅我是否有错误的最佳实践。 我在Google上搜索Devise的内部工作并没有把我带到任何地方,所以我很感激任何帮助!


编辑:这是我的路线文件:

 Rails.application.routes.draw do resources :given_answers get 'students/set_quiz_session' resources :given_answers #change the sign_in and sign_out routes to /login and /logout devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout'}, :controllers => {:registrations => 'registrations'} resources :quiz_sessions, :answers, :questions, :quizzes, :courses # Setup static pages get 'teacher/quiz_start', to: 'pages#create_session', :as => :teacher_start_quiz get 'teacher/quiz_question', to: 'pages#show_question', :as => :teacher_question get 'teacher/quiz_question_result', to: 'pages#show_question_result', :as => :teacher_question_result get 'teacher/quiz_result', to: 'pages#show_quiz_result', :as => :teacher_quiz_result get 'teacher/home', to: 'pages#show', :role => "teacher", :page => "home", :as => :teacher_home get 'student/quiz_start', to: 'pages#join_session', :as => :student_start_quiz get 'student/home', :role => "student", :page => "home", :as => :student_home get ':role/:page', to: 'pages#show' root to: redirect('teacher/home'), :role => "teacher", :page => "home" mount ActionCable.server => '/cable' end