Anyone know the answer for 4. routes for ruby on rails?


#1

I type:

get 'welcome' => 'pages#home' on the second line of the routes.rb file and it tells me:

Oops! The test returned an error. Maybe you have a syntax error, or a typo. Hide error.app/controllers/pages_controller.rb:2:in
<class:PagesController>': undefined methodget' for
PagesController:Class (NoMethodError)

ANYONE KNOW THE ANSWER???


#2

Hi Zak,

Could you please give a link to the exercise you're on?
Thanks!


#3

https://www.codecademy.com/en/courses/learn-rails/lessons/start/exercises/start-routes?action=resume


#4

The line of code you posted didn't cause any trouble for me. Could you please post the entire code in pages_controller.rb and routes.rb?
Thanks!


#5

pages_controller.rb

class PagesController < ApplicationController
get 'welcome' => 'pages#home'
def home
end
end

routes.rb

Rails.application.routes.draw do
get 'welcome' => 'pages#home' # The priority is based upon order of creation: first created -> highest priority.

# You can have the root of your site routed with "root"
# root 'welcome#index'

# 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


#6

Thanks for doing that, Zak.
The problem is on line 2 of pages_controller.rb:

class PagesController < ApplicationController
  get 'welcome' => 'pages#home'
    def home
    end
end

^ should be this:

class PagesController < ApplicationController
  def home
  end
end

I hope this helps!


#7

Thanks. I just tried it and it worked.