Hy everybody,
first, excuse me for my english, I’m french (sorry for that :D).
My actual problem is that I encountered a NoMethodError when I
tried to access to a session value that is not nil. I’m doing some ajax
calls and I afffect the key/value and access to session variable in the
same controler “injection_controller.rb”. I also access to session in a
view _infos_fichiers_xml.html.erb.
The access to session in the view _infos_fichiers_xml.html.erb
does not cause any problem.
BUT
When I tried to access to the session in injection_controller.rb,
I get a :
[color=red]NoMethodError (You have a nil object when you didn’t
expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?):[/color]
The session contains an Array of objects “XmlFile” and I’ve configured
my environement.rb to use the memory store :
config.action_controller.session_store = :memory_store
This is my injection_controller.rb session key/value affectation
code :
def analysis_repository
.....
session[:list_xml] = create_XML_file_obj(false)#put an array of
XmlFile objects in the session
render :update do |page|
page[:liste_fichiers_xml].replace_html render(:partial =>
"infos_fichiers_xml")
page[:liste_fichiers_xml].show
end
end
No error are generated when I access to session[:list_xml] from the view
_infos_fichiers_xml.html.erb like this :
<% session[:list_xml].each{|xml_file| %>
<legend><%=h xml_file.name%></legend>
<% } %>"
But in an another method in injection_controller.rb :
def inject_data(name_xp,desc_xp)
test = session[:list_xml]
puts "#{test.nil?}"#this line print false
test.each do|xml_file|#this line generate the error
puts xml_file.name
end
end
So, it’s very strange, and when I look at the session with <%= debug
session %> I can see the @data that contains my XmlFile array !
I probably do something bad !
I you have any ideas ?!
Thank you for advance !