What we are trying to do is to store a chunk of erb code in a string and then render the code in run time in erb.
Here is the chunk of erb code which is stored as string:
<tr>
<th>#</th>
<th><%= t('Date') %></th>
<th><%= t('Project Name') %></th>
<th><%= t('Task Name') %></th>
<th><%= t('Log') %></th>
<th><%= t('Entered By') %></th>
</tr>
<% @logs.each do |r| %>
<tr>
<td><%= r.id %></td>
<td><%= (r.created_at + 8.hours).strftime("%Y/%m/%d")%></td>
<td><%= prt(r, 'task.project.name') %></td>
<td><%= prt(r, 'task.task_template.task_definition.name') %></td>
<td><%= prt(r, :log) %></td>
<td><%= prt(r, 'last_updated_by.name') %></td>
</tr>
<% end %>
t() is the translation method for internationalization.
How can we insert the above erb code stored in string back to erb file below for rendering (in pseud code) ?
<table class="table table-striped">
<% erb_code = retrieve(chunk_of_erb_code)%>
<% erb_code here for rendering %>
</table>
Is there a solution for the problem? Thanks for help.
UPDATE:
Working code with render inline (by kamesh):
<% erb_code = find_config_const('task_log_view', 'projectx')%>
<%= render inline: ERB.new(erb_code).result(binding) %>
For a good practice, variable erb_code could be moved into the controller.