javascript - User-editable table with variable number of rows in Rails -


I am running Rail 3.2.11. I am working on a simple wiki project because I learn rail and javascript. What I want to do is to store a two-column table in my database, whose content and number of rows can be edited by users, and using jQuery to add the form to a new table row on a button click You can. The table is stored in the form of a hash with hash for each row column. I.e. {"row1" = & gt; {"Head" = & gt; "First column / header content", "tail" = & gt; "Second column / data content"}, "row2" = & gt; {"Head" = & gt; "First column / header content", "tail" = & gt; The part of my _form.html.erb looks like this:

   gt; Add Row & lt; / Button & gt; & Lt; / Div & gt;  

I'm displaying the table on my page like:

   & Lt;% = line [1] ['tail]]% & gt; & Lt; / Td> & Lt; / TR & gt; & Lt;% end% & gt; & Lt; / Table & gt;  

and my Node.js file is the following:

  $ (document) .ready (function () {$ ('# header'). ( 'script load') var newIndex = 0 $ ( '# add_table_row'). click (function () {$ ( '. sidebar_img'). append ( 'onclick event active') var prevIndex = newIndex bridesmaid prevRow = $ ( '#node_table_row') newIndex = newIndex + 1 var newRow = prevRow.clone (right) .attr ( 'id', 'node_table_row _' + newIndex) newRow.find ( '# node_table_row_head') attr ({ID :. 'node_table_row_head_ '+ newIndex, name:' node [table] [row '+ newIndex +'] [head] '}) newRow.find (' # node_table_row_tail ') attr ({ID :.' node_table_row_tail _ '+ newIndex, name:' Node [table] [line '+ newindex + "] [Tail] '}) Nirav. After (Prerov)})}};  

I do when I click on the" Add Row "button, then I get my confirmation that The onclick incident has been recognized, but the forms have not been added, am I completely coming in the wrong way? It seems like there will be an easy way to go about this kind of way.

have you tried using jQuery insertAfter () method? Use jQuery to select the table then use. children (). InsertAfter (newRow);


Comments