Re: rails 2D array access in Helper method

leo nike
Wed, 06 Nov 2013 18:08:58 -0000

Hi, once again thanks for you code contribution, that helped me to see
problem from a different perspective a little bit. I liked both of your
code snippets, and 1st one in particular (since i actually understand
it)

There is only one issue though, if I try to run code below on trough
jQuery (when the checkbox is checked) it wouldnt really execute
anything.
That''s what I had problem before, and I know the problem is not with
jQuery method. I cant easily modify code to
$("#div2").html("<%= ''hello''%>") and
it would print ''hello'' in that div.
So, there is something that jQuery doesnt see in iether get_array or
format_table method. I''ve tried to merge all the 4 methods into one and
run it as one method, but it still wouldnt work. Would you please check
it one again, and let me know what could be changed?

And yes, I just want to output the result of parsed array into html
code. I dont really care how, it''s just I know only Jquery .html()
method and it seems relatively simple.

Thank you very much

def get_array()
  # sqlite stuff as you have it
  format_table(result)
end

def format_table(data)
out = " \n"
  out += data.map do |row|
    format_row(row)
  end.join("\n")
out += "\n \n"
end

def format_row(row)
out = " "
  out += row.map do |cell|
    format_cell(cell)
  end.join
out += " "
end

def format_cell(cell)
" #{cell} "
end

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

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit