Ray
Ray

Reputation: 4947

Rails routing gives file not found error

I have a Ruby on Rails application with the following entries in routes.rb:

  get '/teachers/welcome', to: 'teachers#welcome'

Which means that if I type: http://localhost:3000/teachers/welcome then I should be able to see the welcome view from the teachers controller. But I keep getting File Not Found error. I'm new to Ruby so bear with me.

When I look at the application, the files are there:

app/controllers/teachers_controller.rb

app/views/teachers/welcome.html.erb

Upvotes: 0

Views: 287

Answers (4)

mtkcs
mtkcs

Reputation: 1716

You have to remove the first slash

get 'teachers/welcome' => 'teachers#welcome'

Your Controller:

# app/controllers/teachers_controller.rb
class TeachersController < ApplicationController
  def welcome
  end
end

Note: you can use a generator to create it automatically:

rails generate controller teachers welcome

Upvotes: 0

a2k11
a2k11

Reputation: 1

Make sure you have everything named properly, like the controller and the view.

app/controllers/teachers_controller.rb

class TeachersController < ApplicationController
  def welcome
  end
end

app/views/teachers/welcome.html.erb

Upvotes: 0

Tony Tawk
Tony Tawk

Reputation: 82

Please watch the naming of you model (without s) but your contoller with s .. and the view name have to match the action name . And run rake routes to check your working routes . + be carefull of the routes order in the routes.rb file .. and will not have any problem in your life with the routes

Upvotes: 1

igavriil
igavriil

Reputation: 1021

Assuming that you have a method(action) 'welcome' in your controller try this

get 'teachers/welcome' => 'teachers#welcome'

Upvotes: 0

Related Questions