0

I am new in ROR

I want integrate html code with ROR Code Like PHP

This is php Exmple code:-

$output='';

$output.='<div>how r you?</div>';
$output.='<div> fine</div>';

echo $output;

Output

how r you? fine

Help how to integrate html with ROR code? Like php see above the php code.

Kwaghray
  • 39
  • 2
  • 9
Abid Hussain
  • 7,724
  • 3
  • 35
  • 53

5 Answers5

0

Use String#+, it's like PHP's . String operator:

output = "Hello"
output += " world!" # same as output = output + " world!"

Or use String#<<

output = "Hello"
output << " world!"

Which is the same as String#concat:

output = "Hello"
output.concat(" world")

The last two examples modify the contents of output.

zwippie
  • 15,050
  • 3
  • 39
  • 54
0

You can use helpers to integrate html code with the ROR code.

In the helpers itself you can generate tags as <p> or <div> and close them after inserting the data from the back end

In short you can generate html pages dynamically in the helpers. Helpers are particularly for views

You can refer to the below link for more clarity

Using helpers in rails 3 to output html

Kwaghray
  • 39
  • 2
  • 9
0

In rails there is a available method called html_safe(). You can use this to integrate html code in .html.erb file

controller:- @test = ("<h1>Test case</h1>").html_safe html.erb:- <%= @test %>

0

Try below code to print html on page:

Controller

@data = "<h1>Testing...</h1>"
@data=+ "<h2>Hello</h2>"

view

<%= @data.html_safe %>

OR

<%= raw(@data) %>
puneet18
  • 4,341
  • 2
  • 21
  • 27
0

Controller

@data = "<h1>Testing...</h1>"
@data=+ "<h2>Hello</h2>"

Views

<%= @data.html_safe%>
Desingh
  • 103
  • 1
  • 5