small medium large xlarge

Avatar_pragsmall
26 Sep 2011, 03:14
Andor Chen (2 posts)

hi, i am a Rails newcomer, and when i came across to the Iteration F4, i was stuck on the “Helper methods”, here is the details

when i add the @hidden_div_if@ method to @application_helper.rb@:

def hidden_div_if(condition, atrrs = {}, &block)
  if condition
    atrrs["style"] = "display:none"
  end
  content_tag(:div, attrs, &block)
end

and change the view in @application.html.erb@:

<%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %>
  <%= render @cart %>
<% end %>

and the i refreshed the homepage in browser, i got a “NameError in Store#index” error said:

undefined local variable or method `attrs' for #<#<Class:0x0000010299f630>:0x00000102984330>

since newcomer am i, i just haven’t figured out what just happend and how to fix this error.

did anybody have this error? if not, why it happened to me?

please help me newcomer.

thx a lot.

Samr_small_pragsmall
26 Sep 2011, 19:43
Sam Ruby (634 posts)

You need to be abbreviate consistently. In the book, the name of the second parameter is attributes. You have two occurrences of atrrs (two r’s), and one of attrs (two t’s).

Avatar_pragsmall
27 Sep 2011, 05:31
Andor Chen (2 posts)

so shame for myself, just a typo

thank you Sam very much

You must be logged in to comment