Jump to content

The ultimate community for Ruby on Rails developers.


Photo

output two-demensional array to view through jQuery

rails jquey arrays

  • Please log in to reply
No replies to this topic

#1 stack

stack

    Passenger

  • Members
  • 1 posts

Posted 01 November 2013 - 06:56 PM

Want to simply print out 2d array elements. Method is located in Helper module. Calling helper method from jQuery. At the moment I'm not getting output (=> 0..3) I tried to do iterate through array via .each() method, but it would just print en entire array, however i want to access each element and convert it either to string or integer. can someone point me to possible solution? thanks!

 

          #app/helpers/controller_helper.rb
              def get_array
                        database
= SQLite3::Database.open("test.db")
                        result = database.execute("select * from table1")
                       print_array(result)
             end

             def print_array(array)
                    for i in 0..array.length
                       puts array
[i][i]
                    end
            end

          -------------------------------------------------------------------
          #app/views/controller/file.js.erb
             if($('.check_box1').is(':checked')){
                 $("#div2").html("<%= get_array%>")
             }






Also tagged with one or more of these keywords: rails, jquey, arrays

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users