I have this line of Ruby code generated by rails:
class PostsController < ApplicationController What does < mean?
I have this line of Ruby code generated by rails:
class PostsController < ApplicationController What does < mean?
< is used for Inheritance. In Ruby, a class can only inherit from a single other class.
class PostsController < ApplicationController
in above line of code PostsController (child-class) is inherits from ApplicationController parent-class.
In Rails:
Action Controllers are the core of a web request in Rails. By default, only the ApplicationController in a Rails application inherits from ActionController::Base. All other controllers inherit from ApplicationController. This gives you one class to configure things such as request forgery protection and filtering of sensitive request parameters.
for more info :
What you're saying there is: "Declare a new class called PostsController and inherit the behaviour from ApplicationsController to be used in PostsController".
Basically < is used for Inheritance
More info here
It means that PostsController definition starts by having everything in ApplicationController. while the rest of the definitions will add/replace members/attributes to PostsController.
Using < indicates inheritance. Basically, this means that PostsController will have everything ApplicationController has, except for it's private members. However, you can override methods in the subclass to change the behavior of the methods inherited from the superclass.