I am saving an array of active record objects (college courses) in the
session as session[:course_list]. This is the cart for a registration
controller.
If a student chooses to delete the course from the list I get the :id
as params[:id].
However if I do
session[:course_list].delete_if {|x| x.id ==params[:id]}
does not work.
session[:course_list].delete_at(idx)
works. Ocourse to do this I have to index the list in the view and
insert the value into each link_to.
When I try this in irb the second statement works but the first does
not and does not give any error messages.
What am I missing here? I have stared at this long enough and can’t
figure it out.
It is. I checked in irb using breakpointer. Also when I directly
execute the code in irb with manually entered value nothing happens.
eg.
session[:array_of_objects].delete_if {|x| x.id == “47”}
I am going to try this again with all stale sessions removed.
It is. I checked in irb using breakpointer. Also when I directly
execute the code in irb with manually entered value nothing happens.
eg.
session[:array_of_objects].delete_if {|x| x.id == “47”}
There’s your problem… If you are actually storing Model objects in
that session array, then the id attribute will be an integer. You
can’t directly compare integers to strings and hope to get a match.
Notice:
Thank you very much for your response. I did figure it out yesterday
after mucking around in irb for a while and actutally looked at the
parms hash. Thanks again,
bakki
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.