我遵循本教程
http://guides.rubyonrails.org/getting_started.html,我在第5.1节,但我没有看到/ articles / new /的目录。我应该创建这个,还是在我将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
提前致谢!
答案 0 :(得分:2)
您是否生成了文章控制器?
生成控制器时,它应该在视图中创建一个目录,但不会包含任何erb文件。
答案 1 :(得分:0)
您可以手动创建文件,但最好以rails方式执行,因此您需要生成文章控制器并将其传递给您想要的视图。
举个例子:
rails g controller articles index new show edit
这会创建您的 articles_controller ,其中包含适当的方法供您使用,以及视图,这就是轨道发电机呢!
生成器还在routes.rb文件中创建获取路由,因此请确保删除这些获取路由,因为您已经使用resources :articles
处理路由。