Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Partial counter #38

Closed
amree opened this Issue Feb 18, 2012 · 6 comments

Comments

Projects
None yet
2 participants

amree commented Feb 18, 2012

Is it possible to pass a counter value in the helper method? Or is it already available somewhere?

Owner

nathanvda commented Feb 18, 2012

Could you please explain the use-case: why do you need the numbering?

Owner

nathanvda commented Feb 18, 2012

Check http://guides.rubyonrails.org/layouts_and_rendering.html and search for counter. Normally this should be available for you as well. E.g. comment_counter if you are rendering a list of comments.

@nathanvda nathanvda closed this Feb 18, 2012

amree commented Feb 18, 2012

Thanks for the fast replies and sorry for my late reply. I did try the example given but somehow I got error saying as if the index has not been declared at all. I was actually trying to access any errors for the nested form using the index. For an example, I can do something like this with nested_form gem:

- @catalogue.item_catalogues.each.with_index do |item_catalogue, index|
  = render partial: 'form_item_catalogue', locals: { index: index, item_catalogue: item_catalogue, f: f }
= f.link_to_add "Add an item", :item_catalogues, style: "display: none"
= f.fields_for :item_catalogues, item_catalogue do |i|
  = normal_div_if @catalogue.item_catalogues[index].errors[:item].empty? do
    = i.label :item_id, "Item"
    .input
      = i.collection_select :item_id, Item.all, :id, :nama, {}, class: "chzn-select-nested span5"
      = i.link_to_remove "Delete", class: "btn danger"
      %span.help-inline
        = @catalogue.item_catalogues[index].errors[:item].join(", ")
Owner

nathanvda commented Feb 18, 2012

I am a bit lost. What are you replying to here? Which example did you try? This does not look like cocoon code. Did you try using the item_catalogue_counter as mentioned in the Rails guide?

amree commented Feb 19, 2012

I was in the rush earlier. This is actually some codes from my previous project that uses nested_form gem. What I'd like to do is that I'd like to be able to use something like this:

@catalogue.item_catalogues[index].errors[:item]

I can't do this with cocoon, so, I'm wondering if it's not possible with cocoon or maybe it's just because of my wrong codes. I'll post the code that uses cocoon later.

Owner

nathanvda commented Feb 19, 2012

I do not understand: why not show the errors of the item itself?

You have something like

=f.fields_for :item_catelogues do |item_catalogue|

then you can just do something like item_catalogue.errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment