ActionController::RoutingError(找不到...,期望它在...中定义)

2024-02-17

所以...第一次向 StackOverflow 提问...

我按照 Rails Guides 和 RailsApps Project 将现有的 Rails 4.2.5 应用程序(使用 Ruby 2.2.4)转换为 Rails 5.1.3 应用程序(使用 Ruby 2.4.1)。

启动开发服务器会产生:

Taruns-iMac:Play_Ball tarunchattoraj$ rails s
=> Booting Puma
=> Rails 5.1.3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

这正是我所期望的。

然而,导航到 localhost:3000 会产生 ActionController 错误:

Started GET "/" for 127.0.0.1 at 2017-08-13 11:05:38 -0400
   (0.2ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
  
ActionController::RoutingError (Couldn't find Api::KeepScoresHelper, expected it to be defined in helpers/api/keep_scores_helper.rb):
  
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/welcome_controller.rb:1:in `<top (required)>'

我希望看到我的应用程序在页面上正常运行。

我的问题:

是什么导致了这个 ActionController::RoutingError (无法找到...) 以及如何纠正它?

This question https://stackoverflow.com/questions/34562224/getting-couldnt-find-sessionshelper-expected-it-to-be-defined-in-helpers-ses似乎说到点上了。我尝试了“触摸”所有帮助文件的解决方案,但没有成功。

当我从 Rails 4.2.5 转换到 5.1.3 时,我运行 $ rails app:update我覆盖了大多数文件——那些文件中没有特定于我的应用程序的代码,但我选择不覆盖 config/routes.rb。

配置/routes.rb:

Rails.application.routes.draw do
  resources :alerts
  get 'games/decide_game_view' => 'games#decide_game_view', as: :decide_game_view
  resources :games
  resources :game_hitting_stats
  resources :game_pitching_stats
  resources :locations
  resources :players
  get 'welcome/index'

  get 'welcome/about'



  resources :users do
    resources :players
  end

  resources :sessions, only: [:new, :create, :destroy]
  resources :teams do
    resources :notes
  end

  # namespace :api, defaults: {format: :http} do
  namespace :api do
    match '/texts', to: 'texts#preflight', via: [:options]
    resources :texts, only: [:create]

    match '/keepscore/teams', to: 'keep_scores#preflight', via: [:options]
    get 'keepscore/teams' => 'keep_scores#get_teams', as: :get_teams

    match '/keepscore/roster', to: 'keep_scores#preflight', via: [:options]
    get 'keepscore/roster' => 'keep_scores#get_roster', as: :get_roster

    match '/keepscore/post_game_stats', to: 'keep_scores#preflight', via: [:options]
    post 'keepscore/post_game_stats' => 'keep_scores#post_game_stats', as: :post_game_stats

  end
  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"
  # root 'welcome#index'

  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Example resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Example resource route with more complex sub-resources:
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', on: :collection
  #     end
  #   end

  # Example resource route with concerns:
  #   concern :toggleable do
  #     post 'toggle'
  #   end
  #   resources :posts, concerns: :toggleable
  #   resources :photos, concerns: :toggleable

  # Example resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end
  root 'welcome#index'
end

ActionController 似乎告诉我它找不到 KeepScoresHelper 模块并且它在 helpers/api/keep_scores_helper.rb 中查找。但该文件存在请参阅应用程序控制器和辅助树结构的图片 https://i.stack.imgur.com/hlqFU.png.

helpers/api/keep_scores_helper.rb 的内容:

module API::KeepScoresHelper
end

Gemfile:

source 'https://rubygems.org'

ruby "2.4.1"
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.1.3'
gem 'puma'

gem 'pundit'
gem 'bcrypt'

gem 'active_model_serializers', '~> 0.10.0'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jquery-turbolinks'
gem 'bootstrap-sass'
gem 'figaro'
gem 'pry'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

group :test do
  gem 'pundit-matchers', '~>1.0.1'
end

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'listen'
  gem 'byebug'
  gem 'web-console', '~> 3.5.1'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'rspec-rails'
  gem 'shoulda'
  gem 'faker'
  gem 'factory_girl_rails'
  gem 'rails-controller-testing'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views

  gem 'sqlite3'


end

当然,非常感谢任何帮助......


在 config/environments/development.rb 中,设置:

config.action_controller.include_all_helpers = false

这将使 Helpers 恢复到 Rails 5 之前的行为。每RoR API http://api.rubyonrails.org/v5.1/classes/ActionController/Helpers.html,对于 Rails 5.1.3,“默认情况下,每个控制器将包含所有助手。”在 Rails 5 之前,控制器将包含一个与其名称匹配的助手。进行上述指定的设置将返回到 Pre-Rails 5 的行为。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ActionController::RoutingError(找不到...,期望它在...中定义) 的相关文章

  • Rails 5.1 中的 form_with 搜索字段

    在 Rails 5 1 中 所有表单都必须使用form with In http edgeguides rubyonrails org 5 1 release notes html unification of form for and f
  • 如何在 Rails 5.1 中关闭 BIGINT 主键

    Rails 5 1 迁移生成BIGINT 代替Integer 对于表的主键 变更日志 是否可以在配置中的某处禁用它 如果是这样 如何禁用它 根据拉取请求 不 这在配置级别是不可能的 但事实上你可以强迫id为整数 如下所示 create ta
  • 将数据从 Rails 视图传递到 webpacker 中的 VueJS 组件

    我正在尝试摆弄 Rails 5 1 的新 webpacker gem 以及 VueJS 但无法让我的 erb 视图将数据传递给 VueJS 组件 假设我有一个用户显示视图 view users show html erb 还有我的 Java
  • Rails 4 中的救援_来自 ActionController::RoutingError

    我有以下错误 ActionController RoutingError No route matches GET images favicon ico 我想显示不存在的链接的错误 404 页面 我怎样才能做到这一点 In applicat
  • Ruby on Rails 301 重定向

    我向某些模型添加了 slugs 但由于 SEO 我需要从旧链接进行 301 重定向 老的 http host com foo 1 new http host com foo foo slug 问题 这种情况下如何实现301重定向呢 是否可以
  • Rails - 通过 Active Storage 上传文件后在视图中显示图像

    我有一个正在进行中的项目5 1 2我正在尝试在其上实现活动存储 按照几个在线教程 我可以设置活动存储 并且可以看到保存在其中的数据active storage blobs and active storage attachments tab
  • 资产“logo.png”不存在于资产管道中

    在 Rails 5 1 3 中 我更改应用程序 资产 图像中的徽标文件 然后错误不知道要修复什么 有谁知道吗 The asset logo png is not present in the asset pipeline 已经尝试重新启动r
  • 如何从控制器中包含的模块渲染js模板?

    我在控制器关注点中有一个操作 该操作包含在控制器中 此操作不会呈现在 respond to 块下指定的 js erb 文件 如何正确获取控制器关注点中的操作以成功呈现 js erb 文件 或任何视图 是我的路线有问题吗 模块操作的链接 li
  • 一种型号有多种更新表格

    我想在一页上有多个表格 让我们举个例子来理解我想要的 我有一个管理员页面 假设它是admins show页 我的管理员必须在此页面上的一张表格上更改他的姓名 并在另一张表格上更改他的年龄 我知道我可以创建一个表单 但我想要多个表单 因为这只
  • Rails 3:获取当前名称空间?

    使用方法 layout for namespace 我根据我是在前端还是后端设置应用程序的布局 因为后端使用命名空间 admin 我找不到一种很好的方法来找出我所在的命名空间 我找到的唯一方法是解析 params controller 中的
  • ActionController::Metal 需要什么模块才能传递状态代码进行渲染?

    我有一个使用 ActionController Metal on Rails 4 1 6 的 Api 控制器 如下所示 class Api lt ActionController Metal include AbstractControll
  • ActionController::估值中的UrlGenerationError#new

    我读过其他相关文章UrlGenerationError似乎指向一个单词的单数或复数 但我认为这不是问题所在 当我从valuations form html erb中删除时它起作用 提交 form name tag list readd 然后
  • ActionController::RoutingError(找不到...,期望它在...中定义)

    所以 第一次向 StackOverflow 提问 我按照 Rails Guides 和 RailsApps Project 将现有的 Rails 4 2 5 应用程序 使用 Ruby 2 2 4 转换为 Rails 5 1 3 应用程序 使
  • 使用 Ruby On Rails 进行事务操作

    我在控制器内有一个复杂的操作 可以对数据库执行多个更新查询 我怎样才能做出这个动作行为类似于交易没有任何结构重构 MyModel transaction do begin model update stuff sub model updat
  • 使用 Capistrano 部署 Rails 5.1 / Webpacker 应用程序

    我有一个 Ubuntu 服务器来部署我的 Rails 项目 在我的 Ubuntu 服务器中 我有 RVM 现在我想使用 Rails 5 1 和 webpacker 部署新项目 为了部署这个项目 我在我的 Ubuntu 服务器中安装了 NVM
  • Rails 是否有“未经授权”的例外情况?

    我正在编写一个应用程序 它使用普通的旧 Ruby 对象 PORO 从控制器中抽象出授权逻辑 目前 我有一个名为的自定义异常类NotAuthorized that I rescue from在控制器级别 但我很想知道 Rails 4 是否已经
  • 使用 RSpec 3 和 Rails 4 在控制器测试中查找新创建的记录

    我正在 Rails 4 中制定控制器规范 并且想要测试由控制器操作创建的记录的属性 如何找到新创建的记录 例如 我可以做什么来代替 it Marks a new user as pending do post create params I
  • Rails 5.1.1 弃用警告已更改_属性

    我刚刚从 Rails 5 0 0 升级到 5 1 1 并开始收到大量弃用警告 如下所示 弃用警告 的行为changed attributes代替 after 回调将在下一版本的 Rails 中发生变化 新的 返回值将反映之后调用该方法的行为
  • # Rails 5.1 的未定义方法“map”

    我正在将 Rails 应用程序从 3 2 2 升级到 5 1 4 我直接使用参数时在地图方法上遇到错误 错误 ActionController Parameters 的未定义方法 map 在下一行 assignments params as
  • 使用react_on_rails gem 创建演示项目时的节点问题

    我正在尝试遵循这个tutorial https shakacode gitbooks io react on rails content docs tutorial html使用 gem react on rails 创建一个虚拟项目 我想

随机推荐

  • Inno Setup:选择组件的功能

    我有一个小问题 我需要当您选择一个或两个组件时显示一个页面 但其他的并不是只用单一的组件似乎就有效果 我留下了我正在工作的代码 Setup AppName My Program AppVerName My Program v 1 2 Def
  • Javascript + HTML5 本地存储 [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 所以我正在寻找一个关于 localstorage 的好的速成课程 并用 Javascript 与之交互
  • jQuery - :not() 中的多个选择器?

    我似乎无法进行以下工作 input not type radio type checkbox live click function alert You haven t clicked a radio or checkbox 尝试了几种不同
  • 如何使用moment js和angularjs获取子午线(上午/下午)

    我有一个关于 Moments js 库的问题 我有一个 AngularJS 中的应用程序 其中有六个选择元素 用于年 月 日 小时 分钟和上午 下午格式 我使用以下格式 moment 来构建 m format 日期 YYYY MM DD h
  • 使用 UpdateChildValues 从 Firebase 中删除

    我正在尝试同时从 Firebase 数据库中的多个位置删除数据 The Firebase 文档 https firebase google com docs database ios save data state 删除数据的最简单方法是在
  • 如何设置 $docroot 来为我提供我想要的路径

    我该如何定义 docroot路径 这样我就可以输入我自己的路径 我有代码 docroot getenv DOCUMENT ROOT 当我将它与我的 index php 结合使用时 索引 php docroot getenv DOCUMENT
  • 在 protobuf 中使用 int32 的原因

    在 gpb proto2 标量类型的描述中 https developers google com protocol buffers docs proto scalar https developers google com protoco
  • 以编程方式将谷歌设置为主屏幕自定义启动器中的搜索栏

    我正在创建 我自己的启动器 In that case I want to put我的主屏幕中的快速搜索栏 即 Google now 启动器 我怎样才能做到这一点 我已经浏览了多个线程但没有找到任何相关答案 我不想展示widget picke
  • 等待 TaskEx.Delay

    我正在使用 HttpListener 和 Async CTP class HttpServer IDisposable HttpListener listener CancellationTokenSource cts public voi
  • 请求沙盒测试者用户 ID 的 Apple 验证电子邮件

    我在获取我在 iTunesConnect 中创建的用于购买非消耗性产品的测试用户沙箱 ID 时遇到问题 创建 ID 后我等了一天才尝试使用它们 首先 我根据设备上的 Settings iTunes App Store 确保没有 ID 登录
  • 屏幕更改后的默认 UIAccessibilityElement

    有什么方法可以决定哪个元素首先获得焦点 我尝试在以下方法中使用第二个参数 UIAccessibilityPostNotification UIAccessibilityLayoutChangedNotification element 但没
  • PHPUnit:如何模拟今天的日期而不将其作为参数传递?

    我正在我的班级上测试一种进行日期检查的方法 问题是该方法取决于今天的日期 每天都在变化 这使得测试变得困难 我如何模拟今天的日期 以便我的测试明天仍能通过 我对 PHP 一无所知 但在 Java 和 C 中 我会传递一些描述的 时钟 不是今
  • 如何将 CSV 文件的表值转换为数组?

    我的价值低于我的 CSV 文件的第一列 table border 1 tr th align left First Name th th align left Gender th th align left Nationality th t
  • 这里使用哪个 XML 解析器?

    我正在接收一个 XML 文件作为输入 其大小可能从几 KB 到更多 我通过网络获取该文件 我需要根据我的使用提取少量节点 因此大部分文档对我来说毫无用处 我没有记忆偏好 我只需要速度 考虑到这一切 我得出的结论是 这里不使用 DOM 由于
  • 从 Numpy 数组中的元素创建新的 Numpy 数组

    这题好像想不通对 numpy 非常陌生 我有一个 numpy 形状数组 200 1 1000 1000 对应于 图像数量 通道 x of image y of image 所以我有 200 个图像 每个通道有 1000x1000 像素 我想
  • Java 的 G1 垃圾收集器 (G1GC) 中的类卸载

    在Java 6中我们曾经使用下面的GC配置来防止Perm GenOutOfMemoryException多次重新部署我们的应用程序后 XX UseConcMarkSweepGC XX CMSClassUnloadingEnabled 我们正
  • 函数参数中的 int * 与 int [] 与 int (*)[] 。我应该使用哪一个?

    在 C 编程语言中 有许多不同的方法来声明将数组作为通过指针传递的参数的函数的参数 我准备了一个例子来说明我的意思 它是一个实现std accumulateC 中的函数 它是一个将数组中所有元素相加并返回结果的函数 我可以这样写 int a
  • 在R中的plotly subplot图中,如何只显示一个图例?

    我有一个带有两个图表的基本子图 默认情况下都有一个图例 但我只想看到其中一个 我试过这个 require plotly p1 lt plot ly data iris x Sepal Length y Sepal Width split S
  • 如何在集群环境下实现零宕机部署?

    我需要在我的系统上部署一个主要部署 超过15个ear文件 我的系统是高可用系统 那么我怎样才能在零停机的情况下完成这个部署呢 我的应用服务器是IBM WAS 更新应用程序后 您可以使用 推出更新 http publib boulder ib
  • ActionController::RoutingError(找不到...,期望它在...中定义)

    所以 第一次向 StackOverflow 提问 我按照 Rails Guides 和 RailsApps Project 将现有的 Rails 4 2 5 应用程序 使用 Ruby 2 2 4 转换为 Rails 5 1 3 应用程序 使