Hy everybody, first, excuse me for my english, I''m french (sorry for that :D). My actual problem is that I encountered a [b]NoMethodError[/b] 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 [b]_infos_fichiers_xml.html.erb[/b]. The access to session in the view [b]_infos_fichiers_xml.html.erb[/b] does not cause any problem. BUT When I tried to access to the session in [b]injection_controller.rb[/b], I get a : [color=red][i]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?):[/i][/color] The session contains an Array of objects "XmlFile" and I''ve configured my environement.rb to use the memory store : [i][b]config.action_controller.session_store = :memory_store[/b][/i] This is my [b]injection_controller.rb[/b] session key/value affectation code : [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[/code] No error are generated when I access to session[:list_xml] from the view [b]_infos_fichiers_xml.html.erb[/b] like this : [code]<% session[:list_xml].each{|xml_file| %> <legend><%=h xml_file.name%></legend> <% } %>"[/code] But in an another method in [b]injection_controller.rb[/b] : [code]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[/code] 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 ! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 2, 2:54 pm, Chdem Chdem <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> [code]def analysis_repository > ..... > session[:list_xml] = create_XML_file_obj(false)#put an array of > XmlFile objects in the sessionIs this actually an array or an association proxy that looks like an array ? Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This is an array of objects, complete like this : *********************************** my_fileXml_array = Array.new myFileXml = FileXml.new myFileXml.name = "TEST" myFileXml.description = "TEST" my_fileXml_array << myFileXml *********************************** But if the datatype was a problem, I could''nt access to the session key/value in my "_infos_fichiers_xml.html.erb"view. Just to make a complete answer, these objects are some XmlFile, defined like that : *********************************** class XmlFile < ActiveRecord::Base has_many :wiff_files has_many :protein_in_experiments belongs_to :experiment serialize :bias_infos end *********************************** class CreateXmlFiles < ActiveRecord::Migration def self.up create_table :xml_files do |t| t.string :name t.text :description ... t.references :experiment t.timestamps end end def self.down drop_table :xml_files end end *********************************** I only have the NoMethodError when accessing to the session key/value in an another function than the one where affectation was made, but in the same controler. Is it an envidence ? That you for your help ! Frederick Cheung wrote:> On Jun 2, 2:54�pm, Chdem Chdem <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> [code]def analysis_repository >> � � � ..... >> � � � session[:list_xml] = create_XML_file_obj(false)#put an array of >> XmlFile objects in the session > > Is this actually an array or an association proxy that looks like an > array ? > > Fred-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 2, 6:46 pm, Chdem Chdem <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I only have the NoMethodError when accessing to the session key/value in > an another function than the one where affectation was made, but in the > same controler. Is it an envidence ?If the problem only appears when accessing stuff put in the session by a previous request and happens in development mode it''s probably related to code reloading. In between requests reloads your classes so on subsequent requests your session contains objects of class that rails has thrown out. In general you should avoid sticking large or complicated things in the session - for example you could store an array of ids of the active record objects. You should also know that memory store isn''t a good choice for a production app - separate passenger or mongrel instances won''t share sessions Fred> > That you for your help ! > > Frederick Cheung wrote: > > On Jun 2, 2:54 pm, Chdem Chdem <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> [code]def analysis_repository > >> ..... > >> session[:list_xml] = create_XML_file_obj(false)#put an array of > >> XmlFile objects in the session > > > Is this actually an array or an association proxy that looks like an > > array ? > > > Fred > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok, thanks a lot ! But, these objects are not already saved in the database, so I can not save the ids ! I have to check a lot of things before doing that.........a solution could be to use transactions. How can I rollback after have saved objects ? One more time, thank you Frederick ! Frederick Cheung wrote:> On Jun 2, 6:46�pm, Chdem Chdem <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> I only have the NoMethodError when accessing to the session key/value in >> an another function than the one where affectation was made, but in the >> same controler. Is it an envidence ? > > If the problem only appears when accessing stuff put in the session by > a previous request and happens in development mode it''s probably > related to code reloading. In between requests reloads your classes so > on subsequent requests your session contains objects of class that > rails has thrown out. > > In general you should avoid sticking large or complicated things in > the session - for example you could store an array of ids of the > active record objects. You should also know that memory store isn''t a > good choice for a production app - separate passenger or mongrel > instances won''t share sessions > > Fred-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok, I have more informations : I can read the array from session if I modify my development.rb file : change config.cache_classes = false TO config.cache_classes = true like in production. But of course, I have to restart the server each times I modify my code to see the results. Is it a cache bug in Rails ? Very strange ! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 3, 4:39 pm, Chdem Chdem <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Ok, I have more informations : > > I can read the array from session if I modify my development.rb file : > change > config.cache_classes = false > TO > config.cache_classes = true > > like in production. But of course, I have to restart the server each > times I modify my code to see the results. > > Is it a cache bug in Rails ? Very strange ! >It''s a known side effect of the code reloading stuff, but as I said above, the memory store is not going to be a good solution for deployment so if I were you I''d try and find a way not to rely on it. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
why topic starter, not use cookie store? Ivan Nastyukhin dieinzige-BUHhN+a2lJ4@public.gmane.org On Jun 3, 2010, at 8:04 PM, Frederick Cheung wrote:> > > On Jun 3, 4:39 pm, Chdem Chdem <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Ok, I have more informations : >> >> I can read the array from session if I modify my development.rb file : >> change >> config.cache_classes = false >> TO >> config.cache_classes = true >> >> like in production. But of course, I have to restart the server each >> times I modify my code to see the results. >> >> Is it a cache bug in Rails ? Very strange ! >> > > It''s a known side effect of the code reloading stuff, but as I said > above, the memory store is not going to be a good solution for > deployment so if I were you I''d try and find a way not to rely on it. > > Fred > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Because cookie store imply a strict size limit of 4kB...... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 3, 5:46 pm, Chdem Chdem <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Because cookie store imply a strict size limit of 4kB...... >If you hitting that limit you are usually doing it wrong (database sessions can contain larger objects though) Fred> -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
if u store models, at session - u are wrong u should save, only ids to db, may be drafts, buts 4kb its normal for 99.8% situations Ivan Nastyukhin dieinzige-BUHhN+a2lJ4@public.gmane.org On Jun 3, 2010, at 8:46 PM, Chdem Chdem wrote:> Because cookie store imply a strict size limit of 4kB...... > > > > > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.