ruby on rails - RoR, how does a "onclick event" work on "check_box_tag" -


i working on application using rails 4. in page, have checkbox want store in user session hash.

following code:

# show.html.erb ... <%= check_box_tag "", "", staytuned_get(some_id), onclick: staytuned_swap(some_id) %> ...  # myhelper.rb def staytuned_get(some_id)   session["staytuned_#{some_id}"] || false end  def staytuned_swap(some_id)   session["staytuned_#{some_id}"] != session["staytuned_#{some_id}"] end 

staytuned_get returns false if "staytuned_#{some_id}" not set or false. otherwise, returns true. staytuned_swap swaps boolean session variable (from true false , vice versa).

unfortunately, session["staytuned_#{some_id}"] false, after click , refresh.

can solve this, thank you.

this not how works in browser. when onclick: staytuned_swap(someid), calls function, return false (a variable equal ...) , use onclick attribute. want javascript doing ajax on click.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

javascript - Backbone.js getting target attribute -

html - Repeat image to extend header to fill screen -