idkPlsHelp
idkPlsHelp

Reputation: 29

Ruby on Rails Tutorial /articles/new

I'm following this tutorial http://guides.rubyonrails.org/getting_started.html, I'm on section 5.1, but I don't see a directory for /articles/new/. Am I supposed to create this or should this already have been done when I added resources :articles to config/routes.rb? My /config/routes.rb looks like:

 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

Thanks in advance!

Upvotes: 0

Views: 97

Answers (2)

bntzio
bntzio

Reputation: 1324

You could create the files manually, but it is better to do it the rails way so you need to generate the articles controller and pass it the views you want to have.

As an example:

rails g controller articles index new show edit

This creates your articles_controller with the proper methods already there for you to work with, as well as the views, that is what the rails generators does!

The generator also created get routes in the routes.rb file, so make sure to delete those get routes, because you already are handling the routes with resources :articles.

Upvotes: 0

kkomaz
kkomaz

Reputation: 261

Did you generate your articles controller?

When you generate a controller it should create a directory in your view but will not have any erb files in it.enter image description here

Upvotes: 2

Related Questions