I have this: <%= @tech_standard.category + " " + @tech_standard.point + "." + @tech_standard.subpoint %> I get this error: cannot convert Fixnum into String point and subpoint are number. How do I concatenate those values? Seth Buntin Web Resources Coordinator Kentucky Academy of Technology Education Murray State University -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060213/3a8d807f/attachment.html
On Feb 13, 2006, at 2:40 PM, Buntin, Seth - KATE wrote:> I have this: > > > > <%= @tech_standard.category + " " + @tech_standard.point + "." + > @tech_standard.subpoint %> > > > > I get this error: > > > > cannot convert Fixnum into String > > > point and subpoint are number. > > > > How do I concatenate those values?@tech_standard.category + @tech_standard.point.to_s + @tech_standard.subpoint.to_s Or if you actually want to add the numbers first and then concatenate their sum to the category string: @tech_standard.category + (@tech_standard.point + @tech_standard.subpoint).to_s -- Jason Perkins
I hate that :) It gets you in the views. .to_s is your friend. <%= @tech_standard.category + " " + @tech_standard.point.to_s + "." + @tech_standard.subpoint.to_s %> -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Buntin, Seth - KATE Sent: Monday, February 13, 2006 2:41 PM To: rails@lists.rubyonrails.org Subject: [Rails] Concatenation I have this: <%= @tech_standard.category + " " + @tech_standard.point + "." + @tech_standard.subpoint %> I get this error: cannot convert Fixnum into String point and subpoint are number. How do I concatenate those values? Seth Buntin Web Resources Coordinator Kentucky Academy of Technology Education Murray State University -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060213/9de5cb83/attachment.html
Thanks... That did it. _____ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Hogan, Brian P. Sent: Monday, February 13, 2006 2:53 PM To: rails@lists.rubyonrails.org Subject: RE: [Rails] Concatenation I hate that :) It gets you in the views. .to_s is your friend. <%= @tech_standard.category + " " + @tech_standard.point.to_s + "." + @tech_standard.subpoint.to_s %> -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Buntin, Seth - KATE Sent: Monday, February 13, 2006 2:41 PM To: rails@lists.rubyonrails.org Subject: [Rails] Concatenation I have this: <%= @tech_standard.category + " " + @tech_standard.point + "." + @tech_standard.subpoint %> I get this error: cannot convert Fixnum into String point and subpoint are number. How do I concatenate those values? Seth Buntin Web Resources Coordinator Kentucky Academy of Technology Education Murray State University -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060213/d97f78f9/attachment-0001.html
Hi, You shouldn''t even need to use to_s if you print it as a string to start with. <%= "This is a string with vars in it: #{@tech_standard.category} #{@tech_standard.point} #{@tech_standard.subpoint}" %> Eric Buntin, Seth - KATE wrote:> > Thanks? > > That did it. > > ------------------------------------------------------------------------ > > *From:* rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] *On Behalf Of *Hogan, > Brian P. > *Sent:* Monday, February 13, 2006 2:53 PM > *To:* rails@lists.rubyonrails.org > *Subject:* RE: [Rails] Concatenation > > I hate that :) It gets you in the views. > > .to_s is your friend. > > <%= @tech_standard.category + " " + @tech_standard.point.to_s + "." + > @tech_standard.subpoint.to_s %> > > -----Original Message----- > *From:* rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] *On Behalf Of *Buntin, > Seth - KATE > *Sent:* Monday, February 13, 2006 2:41 PM > *To:* rails@lists.rubyonrails.org > *Subject:* [Rails] Concatenation > > I have this: > > <%= @tech_standard.category + " " + @tech_standard.point + "." + > @tech_standard.subpoint %> > > I get this error: > > |cannot convert Fixnum into String| > > point and subpoint are number. > > How do I concatenate those values? > > Seth Buntin > > Web Resources Coordinator > > Kentucky Academy of Technology Education > > Murray State University > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Eric Goodwin http://www.ericgoodwin.com
Bah, thats all old school stuff, and I cringe at its site...try this! :) <%= "#{@tech_standard.category} #{@tech_standard.point}.#{@tech_standard.subpoint }" %> Ahhh..thats better! And no need for any to_s methods on the way...and this is all pure Ruby, no Rails magic here. -Nick
Yup... But all those {} hurt my brain. That''s why I gave up PHP :) (the real reason is that I always forget about that!) -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Nick Stuart Sent: Monday, February 13, 2006 3:03 PM To: rails@lists.rubyonrails.org Subject: Re: [Rails] Concatenation Bah, thats all old school stuff, and I cringe at its site...try this! :) <%= "#{@tech_standard.category} #{@tech_standard.point}.#{@tech_standard.subpoint }" %> Ahhh..thats better! And no need for any to_s methods on the way...and this is all pure Ruby, no Rails magic here. -Nick _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Heh, I would agree with you in almost any case but this! :) Curly braces are your friend here. On 2/13/06, Hogan, Brian P. <HOGANBP@uwec.edu> wrote:> Yup... But all those {} hurt my brain. That''s why I gave up PHP :) > > (the real reason is that I always forget about that!) > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Nick Stuart > Sent: Monday, February 13, 2006 3:03 PM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] Concatenation > > > Bah, thats all old school stuff, and I cringe at its site...try this! > :) > > <%= "#{@tech_standard.category} > #{@tech_standard.point}.#{@tech_standard.subpoint }" %> > > Ahhh..thats better! And no need for any to_s methods on the way...and > this is all pure Ruby, no Rails magic here. > > -Nick > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >