I am new to Rails. Can someone please explain to me the concept of string concatenation using variables in view page and the controller?
For example :
In controller Code :
def show
@firstname = 'Test'
@lastname = 'User'
end
In view page :
Full Name : <%= "#{@firstname} #{lastname}" %>
For further details Click Here
Scenarios:- If you want to keep two variables on View page and add concatenation for those then use of space is necessary.
View page:
<%
var string_1 = "With"
var string_2 = "Rails"
var addition_1 = string_1 + string_2;
var addition_2 = string_1 + " " + string_2
%>
<h1> First Addition -> #{addition_1} </h1>
<h1> Second Addition -> #{addition_2} </h1>
Output :
First Addition -> WithRails
Second Addition -> With Rails
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With