Rails 3.2.12 and Ruby 1.9.3 and Haml

I would like to use the count of attribute to control the display of a 'link\_to "remove"', but I am having problems with setting up the logic.

Following is some code from my form as it is currently:

```
    .field
      = codeline.label :name, "Units Alloc"
      %br/
      = codeline.text_field :units_alloc, :precision => 6, :scale => 2, :size => 10,
       :class => "ui-state-default"
      = codeline.hidden_field :_destroy
      = link_to "remove", '#', class: "remove_fields"

```

this works well but I have the 'remove' link showing up and I would prefer it to only show if there are two :units\_alloc attributes.

This is what I tried:

```
    .field
      = codeline.label :name, "Units Alloc"
      %br/
      = codeline.text_field :units_alloc, :precision => 6, :scale => 2, :size => 10,
       :class => "ui-state-default"
      - if :units_alloc.count > 1
      = codeline.hidden_field :_destroy
      = link_to "remove", '#', class: "remove_fields"

```

and here is my error:

```
       NoMethodError in Contracts#new

       Showing /home/tom/rails_projects/tracking/app/views/contracts
       /_codeline_fields.html.haml where line #9 raised:

       undefined method `count' for :units_alloc:Symbol

```

if I use units\_alloc in the argument instead of the symbol, I still get an error:

```
        NameError in Contracts#new

        Showing /home/tom/rails_projects/tracking/app/views/contracts
        /_codeline_fields.html.haml where line #9 raised:

        undefined local variable or method `units_alloc' for
        #<#<Class:0xadbde90>:0xa8956e8>

```

I tried to use 'codeline.units\_alloc' but this did not work and the same error was flagged.

Any suggestions, or pointers to help me resolve this issue?

Thanks.

Solution: Thanks to James Scott Jr.

app/controller/contracts\_controller.rb

```
  def New
     @show_remove = false
     ....
     ....
   end

```

app/views/contracts/\_codelines\_fields.html.haml

```
   .field
      = codeline.label :name, "Units Alloc"
      %br/
      = codeline.text_field :units_alloc, :precision => 6, :scale => 2, :size => 10,
       :class => "ui-state-default"
      - if @show_remove
          = codeline.hidden_field :_destroy
          = link_to "remove", '#', class: "remove_fields"
      - else
         - @show_remove = true

```

And that did it ... the remove button only shows in the second and subsequent row of attributes.