[英]Ruby on Rails Tutorial /articles/new
我正在按照本教程http://guides.rubyonrails.org/getting_started.html进行操作 ,位于5.1节中,但是没有找到/ articles / new /的目录。 我应该创建此文件还是应该在向config/routes.rb
添加resources :articles
时完成此操作? 我的/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
提前致谢!
您是否生成了文章控制器?
生成控制器时,它应该在视图中创建一个目录,但其中没有任何erb文件。
您可以手动创建文件,但是最好以rails的方式进行操作,因此您需要生成articles控制器并将所需的视图传递给它 。
举个例子:
rails g controller articles index new show edit
这将创建具有适当的方法供您使用的articles_controller ,以及视图 ,这是rails生成器所做的!
生成器还在route.rb文件中创建了get路由 ,因此请确保删除这些get路由,因为您已经在使用resources :articles
处理路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.