# Save selected checkboxes after remote\_function call

**URL:** <https://www.ruby-forum.com/t/save-selected-checkboxes-after-remote-function-call/150568>\
**Category:** Rails\
**Created:** [October 10, 2008, 1:31am UTC](https://www.ruby-forum.com/t/save-selected-checkboxes-after-remote-function-call/150568 "2008-10-10T01:31:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [October 10, 2008, 1:31am UTC](https://www.ruby-forum.com/t/save-selected-checkboxes-after-remote-function-call/150568/1 "2008-10-10T01:31:41Z")

</div>

I have an A-Z list that controls a list of check\_box\_tag values. So a  
user clicks on a A-Z link, the list of checkboxes are displayed, they  
tic the checkboxes and the value is stored in the session variable,  
and they go on like that until they submit. Once they submit, the  
session variable is looped over and the values are saved.

The A-Z list uses link\_to\_remote to update the list.  
The check\_box\_tags uses a remote\_function call to store the checked  
value in a session variable.

This all works fine. The problem is that when the user selects a  
checkbox and then selects a new A-Z link and then goes back to the  
same A-Z link the checkbox is no longer selected.

\<%= check\_box\_tag(db.id, db.id, session[:selected].include?  
(db), :onclick =\> remote\_function( :url =\> {:action =\> ‘selected’,:cid  
=\> db})) %\> \<%=db.title%\>

def selected  
session[:selected] \<\< params[:cid]  
render :nothing =\> true, :layout =\> false  
end

I know the remote\_function call is adding the object to the  
session[:selected] array, but for some reason  
session[:selected].include?(db) is not returning true.

Any suggestions? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [October 10, 2008, 8:52am UTC](https://www.ruby-forum.com/t/save-selected-checkboxes-after-remote-function-call/150568/2 "2008-10-10T08:52:53Z")

</div>

On Oct 10, 12:30 am, Kim [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I know the remote\_function call is adding the object to the  
> session[:selected] array, but for some reason  
> session[:selected].include?(db) is not returning true.

because db is apparently an activerecord object, but your session  
contains ids

Fred

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [October 11, 2008, 4:39am UTC](https://www.ruby-forum.com/t/save-selected-checkboxes-after-remote-function-call/150568/3 "2008-10-11T04:39:42Z")

</div>

Thanks Fred, but no go. I have tried both:

\<%= check\_box\_tag(db.id, db.id, session[:selected].include?  
(db), :onclick =\> remote\_function( :url =\> {:action =\> ‘selected’,:cid  
=\> db})) %\> \<%=db.title%\>

and

\<%= check\_box\_tag(db.id, db.id, session[:selected].include?  
(db.id), :onclick =\> remote\_function( :url =\> {:action =\>  
‘selected’,:cid  
=\> db.id})) %\> \<%=db.title%\>

Any other suggestions?

On Oct 9, 11:52 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [October 16, 2008, 4:45am UTC](https://www.ruby-forum.com/t/save-selected-checkboxes-after-remote-function-call/150568/4 "2008-10-16T04:45:02Z")

</div>

Kim wrote:

> \<%= check\_box\_tag(db.id, db.id, session[:selected].include?  
> (db.id), :onclick =\> remote\_function( :url =\> {:action =\>  
> ‘selected’,:cid  
> =\> db.id})) %\> \<%=db.title%\>
> 
> Any other suggestions?

session[:selected].include?(db.id.to\_s)

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [October 16, 2008, 6:20am UTC](https://www.ruby-forum.com/t/save-selected-checkboxes-after-remote-function-call/150568/5 "2008-10-16T06:20:18Z")

</div>

yep, that was it. Thanks.

On Wed, Oct 15, 2008 at 7:44 PM, Mark J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> session[:selected].include?(db.id.to\_s)
> 
> –  
> Rails Wheels - Find Plugins, List & Sell Plugins - [http://railswheels.com](http://railswheels.com)
> 
> >

–  
Kim G.  
removed\_email\_address@domain.invalid

“We are all stakeholders in the Karma economy.”
