使用“生成控制器”添加了新的Rails控制器,但无法加载页面

时间:2013-08-12 20:31:25

标签: ruby-on-rails controller

我有一个Rails应用程序,到目前为止只包含后端代码(一个小的自定义工作流引擎,Redis,工头等)。今天我尝试将第一个控制器添加到应用程序中,但是我无法加载新的控制器。

我用过:

rails generate controller CollectedData new --no-test-framework

回来了:

  create  app/controllers/collected_data_controller.rb
   route  get "collected_data/new"
  invoke  erb
  create    app/views/collected_data
  create    app/views/collected_data/new.html.erb
  invoke  helper
  create    app/helpers/collected_data_helper.rb
  invoke  assets
  invoke    coffee
  create      app/assets/javascripts/collected_data.js.coffee
  invoke    scss
  create      app/assets/stylesheets/collected_data.css.scss

我也跑rake routes得到了这个:

collected_data_new GET /collected_data/new(.:format) collected_data#new

但每当我在浏览器中加载http://localhost:3000/collected_data/new时,我都会:

Not Found: /collected_data/new

以下是我的routes.rb文件的内容:

Crows::Application.routes.draw do
  get "collected_data/new"

  # The priority is based upon order of creation:
  # first created -> highest priority.

  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

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

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

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

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

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

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

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'welcome#index'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
  # match ':controller(/:action(/:id))(.:format)'
end

Procfile内容:

redis: redis-server config/redis/redis.conf
clock: bundle exec rake resque:scheduler --trace
cp_resp_poller: bundle exec rake environment resque:work QUEUE=cp_resp_poller
cp_req_sender: bundle exec rake environment resque:work QUEUE=cp_req_sender --trace
server: rails server

我也尝试重启WEBrick。

更新:我注意到Webrick在请求此控制器(或者我尝试添加的任何新控制器)时返回HTTP 404。

固定:请看我自己对这个问题的回答。

1 个答案:

答案 0 :(得分:1)

修复:我通过更改我的config.ru文件来修复此问题。

原始内容是:

require ::File.expand_path('../config/environment',  __FILE__)
run Crows::Application

require 'resque/server'
run Rack::URLMap.new "/resque" => Resque::Server.new

我通过注释掉与Resque相关的上面两行来修复未找到控制器的问题。最后两行是在开发我的应用程序的工作流程/后端部分时添加的,并为Resque启用了基于Web的管理界面。

更新:我现在拥有我的Rails应用程序(以及其Web控制器等)和并行运行的Resque Web管理界面。我通过从config.ru文件中删除最后两行并将以下行添加到我的routes.rb文件中来实现此功能:

resources :resque_web_admin
mount Resque::Server, :at => "/resque"