加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – routes.rb – 不支持控制器名称

发布时间:2020-12-17 03:41:00 所属栏目:百科 来源:网络整理
导读:我有一个特殊的问题.这是routes.rb的一部分,它涉及到: resources :playersmatch '/players/:userid',:to = 'Players#show' 当您访问localhost:3000 / players / 1234时,会出现此错误: ‘Players’ is not a supported controller name. This can lead to
我有一个特殊的问题.这是routes.rb的一部分,它涉及到:

resources :players
match '/players/:userid',:to => 'Players#show'

当您访问localhost:3000 / players / 1234时,会出现此错误:

‘Players’ is not a supported controller name. This can lead to potential routing problems.

控制器中的相关代码:

def show
  begin
    if Player.find_by(:uid => :userid) then
      @playerattributes = Player.find_by(:uid => :userid) 
      if player[:profile_complete] == true then
        @playerinfo = {
            :age => player[:age],:team => player[:team],:position => player[:position]
        }
      else
        @playerinfo = 0 
      end
    end
    player = Player.find_by(:uid => :userid)[:info]
rescue ActiveRecord::RecordNotFound
    redirect_to root_url        
    end
end

问题并没有就此结束.当页面加载时(它有时随机工作),这一行起作用:
如果是Player.find_by(:uid =>:userid)那么
使用PostgreSQL,显示查询.它不是使用URL中的:userid值(即localhost:3000 / players / 1234将是1234),而只是输入文本“userid”.

我错过了一些明显的东西吗

真的很感激任何帮助.

解决方法

更改

match '/players/:userid',:to => 'Players#show'

match '/players/:userid',:to => 'players#show'

Read more.

要读取控制器中的用户ID值,请使用params [:userid],而不仅仅是:userid.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读