Forum: Ruby on Rails Save selected checkboxes after remote_function call

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2008-10-10 01:31
(Received via mailing list)
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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-10 08:52
(Received via mailing list)
On Oct 10, 12:30 am, Kim <Kim.Gri...@gmail.com> 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
8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2008-10-11 04:39
(Received via mailing list)
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 Cheung <frederick.che...@gmail.com>
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark James (Guest)
on 2008-10-16 04:45
(Received via mailing list)
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
8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim Griggs (Guest)
on 2008-10-16 06:20
(Received via mailing list)
yep, that was it. Thanks.

On Wed, Oct 15, 2008 at 7:44 PM, Mark James <mrj@bigpond.net.au> wrote:

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


--
Kim Griggs
kim.griggs@gmail.com

"We are all stakeholders in the Karma economy."
This topic is locked and can not be replied to.