rails - can onclick work with a method as well as javascript? -


if use following line set onchange action pointing javascript function, seems work.

<% @documents.each |document| %>   <td>< %= check_box_tag "document_ids[]", document.id, checked_flag,   :onchange =>  "myfunction(#{document.id})"   %></td> 

however, if try point def/method, not work expected. appears method called each line displayed. thought onchange/onclick called action if there change or click.

<td><%= check_box_tag "document_ids[]", document.id, checked_flag, {:onchange =>  handle_checkboxes(document.id,checked_flag)}   %></td> 

does ruby/rails allow call method onchange/onclick checkbox_tag?

my goal build array can use in find show documents checked.

def handle_checkboxes(id,flag)   $doc_ids.push(id.to_s)   $test2[id] = 'push'   $test3 = 'we arrived' end 

if use checkbox_tag method variables

$doc_ids.inspect["9999999", "21", "22", "23", "24", "25", "26", "27", "28", "29"]

$test2.inspect ["initial", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, "push", "push", "push", "push", "push", "push", "push", "push", "push"]

but nothing seems change if click on of checkboxes.

i think question lacks serious concept knowledge. onchange triggered on client side, 'in browser'. can't have callback function placed in server triggered event. should having javascript function ajax call intend on server side.

edit : ruby code in page gets executed in server , resulting html , js ones sent browser.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -