私たちがやろうとしているのは、erb
コードのチャンクを a に格納し、そのコードを erbstring
でレンダリングすることです。run time
文字列として格納されている erb コードのチャンクを次に示します。
<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() は国際化のための翻訳メソッドです。
文字列に格納された上記の erb コードを以下の erb ファイルに挿入して (疑似コードで) レンダリングするにはどうすればよいでしょうか?
<table class="table table-striped">
<% erb_code = retrieve(chunk_of_erb_code)%>
<% erb_code here for rendering %>
</table>
問題の解決策はありますか? 手伝ってくれてありがとう。
アップデート:
作業コードrender inline
(kamesh による):
<% erb_code = find_config_const('task_log_view', 'projectx')%>
<%= render inline: ERB.new(erb_code).result(binding) %>
良い方法として、変数 erb_code をコントローラーに移動できます。