首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ruby on Rails教程/文章/新

Ruby on Rails教程/文章/新
EN

Stack Overflow用户
提问于 2015-03-13 12:31:09
回答 2查看 92关注 0票数 0

我正在学习本教程,我在5.1节,但是我没有看到/ http://guides.rubyonrails.org/getting_started.html /http://guides.rubyonrails.org/getting_started.html/的目录。我是应该创建这个,还是应该在我将resources :articles添加到config/routes.rb时就已经创建了?我的/config/routes.rb看起来像这样:

代码语言:javascript
复制
 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

提前感谢!

EN

回答 2

Stack Overflow用户

发布于 2015-03-13 12:51:35

你生成你的文章控制器了吗?

当您生成一个控制器时,它应该在您的视图中创建一个目录,但其中不会有任何erb文件。

票数 2
EN

Stack Overflow用户

发布于 2015-03-13 14:51:57

您可以手动创建文件,但最好使用rails的方式,因此您需要生成文章控制器,并将您希望拥有的视图传递给它。

举个例子:

rails g controller articles index new show edit

这将使用已有的适当方法以及视图创建您的视图,这就是rails生成器所做的事情!

生成器还在routes.rb文件中创建了get路由,因此请确保删除这些get路由,因为您已经在使用resources :articles处理这些路由。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29024903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档