Create a new controllers directory and add a Controller class called ArticlesController in a file named articles_controller.rb as follows:
# controllers/articles_controller.rb
class ArticlesController
attr_reader :env
def initialize(env)
@env = env
end
def index
'<h1>All Articles</h1>'
end
end
- The constructor accepts the
envhash, storing it in an instance variable, so that all action methods can access it. - It contains a single action called
indexwhich returns the response.
In the next lesson, we'll update the router to use this controller.