没有路线匹配[GET]“/ app1”

时间:2014-08-10 05:37:14

标签: ruby-on-rails ubuntu get routes

Rails.root:/ home / chris / rails_projects / app1

我收到有关路线的消息。我的routes.rb文件显示:

我根本不知道如何处理这个问题。我在Virtualbox中使用Ubuntu 12.04。

Rails.application.routes.draw做

  # 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
end

2 个答案:

答案 0 :(得分:1)

您需要创建一个控制器和一个视图来将您的应用程序指向某个地方。

然后,您需要通过编辑路线文件将您的应用路由到该操作。例如,您可以取消注释该行:

 root 'welcome#index'

这将意味着当您导航到根目录(/ app1)上的站点根目录时,将转到欢迎控制器,转到其索引操作。

要了解详情,请查看:http://guides.rubyonrails.org/routing.html#using-root

答案 1 :(得分:0)

Routes

您需要定义应用程序将使用的路由,如下所示:

#config/routes.rb
root 'application#index'

这将引导任何"主页"流量到以下控制器/操作:

#app/controllers/application_controller.rb
Class ApplicationController < ActionController::Base
   def index
   end
end

-

在Rails中路由

您必须记住Rails是一个以MVC为中心的Web应用程序框架

这意味着每次您希望访问&#34; url&#34;时,您需要定义&#34; route&#34;在您的routes.rb文件中。这样做的方法是使用resources方法引用路线文件中的相关controller#actions

#config/routes.rb
root "application#index"
resources :controller_1, :controller_2

由于Rails为object-orientated,您应用的routes通常必须反映其内部的各种资源。大多数人尝试根据推测的&#34; flow&#34;来定义路线。应用程序 - 事实是你想构建它们围绕对象,这通常意味着控制器和/或模型