I
I
Ivan Nesterovich2015-05-30 13:13:10
Ruby on Rails
Ivan Nesterovich, 2015-05-30 13:13:10

What is the risk of using ActiveRecord queries in a view?

I want to implement the ability to connect widgets. And in my opinion it's easier to make a partial with a request to the bazooka and immediately draw it. But there are suspicions that after me it may create some problems. Can anyone more experienced suggest possible problems?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
thepry, 2015-05-30
@thepry

Yes, it's just that such code is more difficult to maintain and debug. Your code for getting data from the model will be in two places: the controller and the view. If you want to use the same data in another partial'e, it will become very bad. Other programmers will find it difficult to maintain such code. they don't listen for requests inside views.
I don't think anything fatal will happen. It's just bad practice.

E
Eugene Burmakin, 2015-05-30
@Freika

Speed. Views will take longer to render. for the experiment, take out the maximum logic from the model-controllers to the views and look in the logs for the duration of their loading. Before and after.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question