Get content from an HTML element in Rails

I am looking for a way to get the contents of my div in my Rails view. I would like to have literal HTML content, so only HTML and without Rails I thought inner_html would work, but I get an RJS exception (TypeError: $ ("content"). InnerHtml is not a function)

Does anyone know how I can get the content? Thank!

In my controller, I use this code:

def save_test
    render :update do |page|
        page['content'].innerHTML
    end
end

Maybe some other context? I get the HTML form (without the form tags themselves) and put it on the rails form. I want the user to change checkboxes, radio buttons, fill in input fields, etc., And when the user saves, I want the literal text to be changed as a string in order to save it in my database.
The reason for this is that the several forms provided are very different, and they are used only as information, no calculations, etc. No need to do this. So my view is as follows:

form_remote_tag :url=>{:action => 'save_trainee_evaluation' do %>
<div id="content">
  <%= contract_trainer_trainee.evaluation_template %>
</div>
<%= submit_tag 'Opslaan' %>
+3
source share
2 answers

, (, render :update do |page| ..), HTML- (, page['content'].innerHTML = 'Thank you, we received your data.'), ( ).

1) , . ( , , , .) , params JSON . . @evaluation.content = params.to_json.

2) div HTML , . (, HTML, .) :

<% form_remote_tag :url=>{:action => 'save_trainee_evaluation'}, :html => { :onsubmit => "$('content_inner_html').value = $('content').innerHTML;" } do %>
<%= hidden_field_tag 'content_inner_html', :id => 'content_inner_html' %>
<div id="content">
  <%= contract_trainer_trainee.evaluation_template %>
</div>
<%= submit_tag 'Opslaan' %>

HTML params[:content_inner_html].

+2

page["content"].innerHTML.

0

Source: https://habr.com/ru/post/1737004/


All Articles