我正在学习本教程,我在5.1节,但是我没有看到/ http://guides.rubyonrails.org/getting_started.html /http://guides.rubyonrails.org/getting_started.html/的目录。我是应该创建这个,还是应该在我将resources :articles添加到config/routes.rb时就已经创建了?我的/config/routes.rb看起来像这样:
Rails.application.routes.draw do
get 'welcome/index'
# 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'
resources :articles
# 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提前感谢!
发布于 2015-03-13 12:51:35
你生成你的文章控制器了吗?
当您生成一个控制器时,它应该在您的视图中创建一个目录,但其中不会有任何erb文件。

发布于 2015-03-13 14:51:57
您可以手动创建文件,但最好使用rails的方式,因此您需要生成文章控制器,并将您希望拥有的视图传递给它。
举个例子:
rails g controller articles index new show edit
这将使用已有的适当方法以及视图创建您的视图,这就是rails生成器所做的事情!
生成器还在routes.rb文件中创建了get路由,因此请确保删除这些get路由,因为您已经在使用resources :articles处理这些路由。
https://stackoverflow.com/questions/29024903
复制相似问题