0

这部分问题是这个问题的一部分上一个问题

在运行rake routes命令并了解错误分类后,我终于想出了这个窗口,但作为 ROR 的新手,我无法追踪 URL 以产生效果。

这就是结果,我相信它也没有错误 -

正确的

但是我尝试了这些 URL,但没有一个有效:(

http://localhost:3000/
http://localhost:3000/users
http://localhost:3000/user

Routes.rb 文件——

Prjmgt::Application.routes.draw do
  devise_for :users

  # 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'
    root :to => 'home#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
4

3 回答 3

1

您的根 URL 应该可以正常工作。

但是,请注意

/user

在您的路线中不存在任何地方,并且

/users

只能通过发布请求访问。在设计中,这用于使用 post 方法提交表单以创建新用户。

只需在浏览器中打开一个 url 就意味着使用 get 请求,并且没有为/users.

/users/sign_up在您的浏览器中试用,它应该会引导您进入设计的注册页面。

我建议您阅读rails guide on routing

于 2013-01-20T19:50:03.643 回答
0

没有定义http://localhost:3000/,即根目录。并且http://localhost:3000/user根本没有任何意义,因为控制器总是复数。

http://localhost:3000/users对于控制器来说通常没问题,但似乎你正在使用一些用户管理的东西,所以它不接受获取请求。

尝试:http://localhost:3000/users/sign_uphttp://localhost:3000/users/sign_in

于 2013-01-20T19:51:03.713 回答
0

查看您之前的问题,您还没有设置 /users 。尝试添加

resources :users

到你的 routes.rb。

至于设计路线,请尝试访问 http://localhost:3000/users/sign_in]

编辑:

还有这条线,

/:controller/:action/:id

不是字面意思。

这只是 match 方法的一个示例。它应该看起来像

match "/users/:id" => "users#show"

这会将 /users/1 与您的 UsersController 中的 show 方法匹配。

于 2013-01-20T19:53:27.257 回答