From: "David A. Black" Date: 2008-10-16T21:46:31+09:00 Subject: Re: A Ruby block question On Thu, 16 Oct 2008, David Trasbo wrote: > David A. Black wrote: >> Hi -- >> >> On Thu, 16 Oct 2008, David Trasbo wrote: >> >>> can't convert nil into String >>> >>> That doesn't really make sence, does it? >> >> Actually it does, because your block contains a call to puts, and puts >> always returns nil. You probably want your block just to contain a >> string. > > Ah, I see. Let me just explain. Since I'm using Rails I am calling this > method with the block in a view or a template. My template language is > Haml, and this is how it's called: > > - fields_for_setting("site", "name") do |f| > = f.label :value, "Site name", :index => nil > = f.text_field :value, :index => nil > > The = is a short hand for puts as you pointed out. But I don't see other > possibilities than using put, otherwise the text field will not show up > in the view. > > How can I both use puts and make some content appear around the text > field? I'm not a HAML expert, but in general, you don't want to use puts for anything you're outputting in a template. You just want to insert strings. I'm not sure how HAML handles string concatenation of this kind. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!