I am new to Ruby on Rails, and I am not confident about my MVC logic.
I am proceeding in this way:
- I have a model ‘User’
- In my controller, I set an instance variable called
@users = User.all - In my views, I implement my logic like this :
<%= @users.each ... %>
I was asking myself in I could bypass the controller step and write this in my views : <%= User.all.each ... %>
I’d like to use good practices in my project, is the second way acceptable?
in real life operations in controller more complexier then User.all.each
for example
and mode and more other logic
in view you need only to render this object
in my example i use render partial
in view
and in view/_car.html.haml
so, if you whant to change view you changing view
if you whant to change behavior of collecting process you changing controller
if you whant to change behavior of object you changing model
the same things with bugs
all in strict order
the order is good and beautiful