I have the following code:
<table class="table table-bordered table-striped" border="0">
<% @time_line.each do |time_line| %>
<%= render partial: partial_name( get_type(time_line) ), locals: { register: time_line } %>
<% end %>
</table>
@time_line is a variable that concatenates records from multiple models. To complicate matters more, for each type of object, I need a different view (it's a project requirement, I can not change). So, to make it easier to maintain afterwards, I thought of doing it above. The methods codes I used to try to call the partials dynamically:
def partial_name(class_name)
partial_names = {
"Custa" => 'financial',
"Andamento" => 'course',
"Movimentacaoweb" => 'web_movement',
"Publicacao" => 'publication',
"Audiencia" => 'hearing',
"Anotacao" => 'anotation'
}
partial_names[class_name.to_s]
end
def get_type(obj)
obj.class.to_s == 'Mensagem' ? obj.model.to_s : obj.class.to_s
end
For some reason, when I run, it gives the following error:
'nil' is not an ActiveModel-compatible object that returns a valid partial path.
Does anyone know how to explain what I'm doing wrong?