Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-4collection-select

Rails 4 collection_select is MVC violated?


I have a small question about collection_select in Rails 4. When we call in the collection_select all the elements of a table example:

<%= f.collection_select :category_id, Category.all, :id, :name %>

Is MVC violated? In other words: if I have a collection_select in the view of products and it calls Category.all in this view, for me we are violated the MVC pattern. Cause Category.all is something that should be in a Model.

Tell me if I'm in right.


Solution

  • Passing a collection to collection_select as a list of options is not a violation of MVC pattern, it's just how collection_select is seeded with data.