I'm looking for a way to add a variable with increment to add to the id of a div, could anyone tell me the most recommended way to do this?
My difficulty in making this increment is due to cocoon that is used to call this render
<%= link_to_add_association '+', f, :filtro_questoes,
'data-association-insertion-node' => "#filter_q",
'data-association-insertion-method' => "append", id: 'add', class: 'btn btn-primary' %>
already tried to access object attribute , @count , but nothing worked out
obs: If you have a better way of doing this without calling the model attribute, it's also worth = D
I need to improve my ruby knowledge, but I have to finish what I'm doing right away.
model
class Carro < ActiveRecord::Base
attr_accessor :count
belongs_to :person
def self.count(n = 0)
@count = n+1
end
def self.count
@count
end
end
view
<div class="control-group nested-fields">
<div id="carro_div_n <%= f.count %>" class="row form-group" style="border: 1px solid blue; padding: 10px; margin: 10px;">
<div class="field">
<h3>Descrição...</h3>
<%= f.label :carro_id %>
</div>
<div class="field col-xs-3">
<%= f.label :marca_id %>
<%= f.select :marca_id,
options_for_select(
@marcas.collect { |marca|
[marca.name.titleize, marca.id] }, 0), {prompt: 'Selecionar marca'}, { id: 'marcas_select', class: 'form-control'} %>
</div>
<div id="div_modelo_n" class="field col-xs-3">
<%= f.label :modelo_id %>
<%= f.select :modelo_id, options_for_select(@modelos.collect { |modelo|
[modelo.name.titleize, modelo.id] }, 0), {}, { id: 'modelos_select', class: 'form-control' } %>
</div>
<div class="checkbox form-group col-xs-2">
<%= link_to_remove_association "remove tarefa", f, class: 'btn btn-danger' %>
</div>
</div>
</div>