Reputation: 43
I am trying to add rails html code using jquery, but didn't work. Code that i have tried:
<% @user.each do |record| %>
<tr>
<td>
<%= record.name %>
</td>
<td>
<%= record.gender %>
</td>
<%= record.dob %>
</td>
</tr>
<% end %>
<button id="edit_button" class="btn btn-primary btn-sm edit" onclick="editRow();">更新</button>
function editrow(){
var $item = $('.edit').closest("tr").find(".nr");
var name = "<%= text_field 'name', class: 'form-control' %>"
$item[0].innerHTML= name;
}
but it didn't work giving error like name is undefined method. also tried with different, but old value didn't displayed.
Upvotes: 0
Views: 75
Reputation: 163
You can't dynamically insert ERB tags. The order of rendering an ERB goes something like this:
Rails reads ERB and renders HTML+assets ->
HTML+assets get returned to your browser ->
Your browser renders HTML and executes JavaScript
Your browser can't read ERB :(
Can you tell us a bit more about what you're trying to do with the "editrow" function, as well as show us more of the ERB?
Upvotes: 1