I\'m new to all three, and I\'m trying to write a simple contact form for a website. The code I have come up with is below, but I know there are some fundamental problems with
Uhmm, i tried in irb the following:
foo = #{23}
Of course it wont work! the '#' is for comments in Ruby UNLESS it occurs in a string! Its even commented out in the syntax highlighting. What you wanted was:
name = "#{params[:name]}"
as you did in your solution (which is not necessary, as it already is a string).
Btw, the reason why the code does not throw an error is the following:
a =
b =
42
will set a and b to 42. You can even do some strange things (as you accidentally did) and set the variables to the return value of a function which takes these variables as parameters:
def foo(a,b)
puts "#{a.nil?} #{b.nil?}" #outputs 'true true'
return 42
end
a =
b =
foo(a,b)
will set a and b to 42.