General consensus would say this is bad design for making your model tied to
your view.
The better way to do this would be to put a method in a helper and call it
from there if you really don’t want to put the code in your view.
OK, that sounds reasonable but here is more of my situation. I have an
array of objects that I want to display in a view. Each object has to
produce a drop down box. However, each object might be an instance of
three different classes. Currently I have a if elsif elsif end
structure that determines which class the object is from. Then the
drop down box is created based on special rules for that drop down
box. One class needs a drop down box that may or may not use grouped
sections (option_groups_from_collection_for_select). I was hoping to
move the logic to the model and then I would only need this in my view
(or something simliar)
<% objs.each do |o| %>
<%= o.alts_for_select(o.current_id) %>
<% end %>
The elsif (or case) structure is gone which is kind of nice.
General consensus would say this is bad design for making your model tied
to
your view.
The better way to do this would be to put a method in a helper and call it
from there if you really don’t want to put the code in your view.
OK, that sounds reasonable but here is more of my situation. I have an
array of objects that I want to display in a view. Each object has to
produce a drop down box. However, each object might be an instance of
three different classes. Currently I have a if elsif elsif end
structure that determines which class the object is from. Then the
drop down box is created based on special rules for that drop down
box. One class needs a drop down box that may or may not use grouped
sections (option_groups_from_collection_for_select). I was hoping to
move the logic to the model and then I would only need this in my view
(or something simliar)
<% objs.each do |o| %>
<%= o.alts_for_select(o.current_id) %>
<% end %>
The elsif (or case) structure is gone which is kind of nice.
After Nick’s replay I did think about this but about if one of objs
for one of the classes has to produce a grouped select? Argg. Maybe
it’s messy no matter what.
Thanks,
Peter
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.