Wednesday, November 6, 2013

[Rails] Re: rails 2D array access in Helper method

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 = "<table>\n"
out += data.map do |row|
format_row(row)
end.join("\n")
out += "\n</table>\n"
end

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

def format_cell(cell)
"<td>#{cell}</td>"
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/672269d07190cfae6045d5d6d6e6cf6c%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate