I'm new to Ruby on Rails and as a C # developer, when I want to reuse code (for a repository class), I could put it in a base class like <T> to be able to do something like this:
public virtual IEnumerable<T> GetAll() { return Context<T>.GetAll(); }
If I need to do any custom logic, I could of course override the method in my User repository.
In Ruby, I know that you can do this:
class UsersController < ApplicationController
This will allow access to all methods in the ApplicationController and parent classes. When using linings, it generates the following method in each of my child classes:
def index @users = User.all respond_to do |format| format.html
As a result, I have 10 classes that have the same method, but the only difference is "User.all", "Post.all", etc.
How do I make this method generic so that I can put it in the ApplicationController class?
Thanks for any help you can provide to newbies to Ruby on Rails.
source share