(This is probably an easy question, but I didn't find the right words to google my problem)
In my controller I have a query like this:
information = Event.where(name: 'xyz')
Which works fine. In this case, only the model "event" gets queried and not other models like "Blog" or "Post". Instead of writing every query, I just want to call a method, which could look like this:
def find_information (model, word)
information = model.where(name: 'word')
end
So, if I write find_information (Event, xyz), it should do:
information = Event.where(name: 'xyz')
or if I write find_information (Blog, xyz), it should do:
information = Blog.where(name: 'xyz')
I tried this:
model = Event
"#{model}".where(name: 'xyz')
But this throws an "undefined method `where' for "Event":String" error. How do I save the model in a variable? Thanks in advance