I'm building a html helper.
My view looks like this:
= item_view "title", @post.title, :class => 'stuff'
My helper looks like this:
def format_item_data(data)
case data
when Class then ''
when School then school(data)
else data.to_s
end.to_s.html_safe
end
def item_view(label, *args)
data = args.first
formatter = args.second
options = args.extract_options!
options[:class] = "pi #{options[:class]}".strip
text = formatter ? send(formatter,data) : format_item_data(data)
content_tag :div, options do
content_tag(:div, label, :class => "label") +
content_tag(:div, text, :class => "data")
end
end
I get the following error:
{:class=>"pi stuff"} is not a symbol
I'm not sure why its throwing this exception. I followed this tutorial
that says I can pass a hash as part of the argument list:
http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/
Thanks for response
--
Posted via http://www.ruby-forum.com/.
Have you got a field in your model called "class"? If so, I'd change
that, as it's a reserved word, and will cause all sorts of confusion
to Ruby.
On 1 Apr 2011, at 23:22, John Merlino <li...@ruby-forum.com> wrote:
> Hey all,
>
> I'm building a html helper.
>
> My view looks like this:
>
> = item_view "title", @post.title, :class => 'stuff'
>
This means that args.second is your hash of options
>
> def item_view(label, *args)
> data = args.first
> formatter = args.second
So here you set formatter to that hash
> options = args.extract_options!
> options[:class] = "pi #{options[:class]}".strip
>
> text = formatter ? send(formatter,data) : format_item_data(data)
And here you're therefore using that hash as the first argument to send, which makes no sense. Did you mean to call extract_options earlier on?
Fred
>
> content_tag :div, options do
> content_tag(:div, label, :class => "label") +
> content_tag(:div, text, :class => "data")
> end
> end
>
> I get the following error:
>
> {:class=>"pi stuff"} is not a symbol
>
> I'm not sure why its throwing this exception. I followed this tutorial
> that says I can pass a hash as part of the argument list:
>
> http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/
>
>
> Thanks for response
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>