Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法“用户url';对于设计会话控制器:创建_Ruby On Rails_Ruby On Rails 4_Devise - Fatal编程技术网

Ruby on rails 未定义的方法“用户url';对于设计会话控制器:创建

Ruby on rails 未定义的方法“用户url';对于设计会话控制器:创建,ruby-on-rails,ruby-on-rails-4,devise,Ruby On Rails,Ruby On Rails 4,Devise,我有用户模型的授权与设计创业板。我想在路径方法中添加以下内容: #应用程序_controller.rb 受保护的 #根据角色重定向到适当的url 在(资源)的路径中签名后定义 如果当前用户具有角色(:admin) 仪表板路径 elsif当前_用户具有_角色?(:学生) 根路径 结束 结束确保在应用程序控制器上有如下方法 def after_sign_in_path_for(resource) resource.next_step end 下一步是记录创建期间存储在记录中的属性,您可以决定

我有用户模型的授权与设计创业板。我想在路径方法中添加以下内容:

#应用程序_controller.rb
受保护的
#根据角色重定向到适当的url
在(资源)的路径中签名后定义
如果当前用户具有角色(:admin)
仪表板路径
elsif当前_用户具有_角色?(:学生)
根路径
结束

结束
确保在
应用程序控制器上有如下方法

def after_sign_in_path_for(resource)
  resource.next_step
end
下一步
是记录创建期间存储在记录中的属性,您可以决定在此处硬编码其他路径

def after_sign_in_path_for(resource)
 if current_user.has_role?(:admin)
  dashboard_path
 elsif current_user.has_role?(:student)
  root_path
 else
  root_path
 end
end

尝试在代码中添加else条件。这对我有用。我漏掉了这样的东西。

我肯定到现在为止错误一定已经解决了。今天我浏览了一下,为了提及并让其他用户知道(如果有),我将在这里提供一个答案

当在应用程序中重新定义
方法的路径中的after\u sign\u并返回
nil
值时,会引发此错误。根据我最好的客人,提供的片段

def after_sign_in_path_for(resource)
  if current_user.has_role?(:admin)
    dashboard_path
  elsif current_user.has_role?(:student)
    root_path
 end
end
给出错误,因为没有任何条件得到满足,因此返回值为
nil
。为了避免这种情况,您可以始终添加一个
else
条件,如果没有其他条件满足,该条件将得到满足。因此,下面的代码片段应该已经起作用(并且将对其他用户起作用)


希望这对别人有帮助。干杯:)

你能在登录后获得当前用户吗?@ChakreshwarSharma,即使我在路径中对登录后的内容进行了注释,我也会收到此错误。删除方法&写入logger.info(“current\u user=“+current\u user.to\u json”)的内容超级,第一眼看,你得到的输出是什么,你的路由看起来不标准。我指的是Desive建议的方式。你应该检查设计宝石文件。就我个人而言,我会在控制器中配置一个经典的Desive routes并使用before action进行身份验证。@ChakreshwarSharma,未定义的方法
super'表示true:TrueClass,你的意思是什么?抑制。或者如果我删除.super,我得到了:undefined method
to_model'for true:TrueClass,你的意思是什么?杜亚姆
def after_sign_in_path_for(resource)
  if current_user.has_role?(:admin)
    dashboard_path
  elsif current_user.has_role?(:student)
    root_path
  else
   some_other_path || root_path
  end
end