jonsteenbergen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Mar-23 20:24 UTC
Views losing values of Controller instance variables.
Since moving my app from local to my host (and moving from development to production) I''ve run into some very odd issues. I''ve searched around for the past day or so and can''t find anything to answer my query! So I''m hoping someone else has run into this. My instance variables are losing their values when trying to display them in a view. Sometimes. I''ve got a projects section The index method in the controller looks like def index @projects = Project.find(:all) @test = ''test'' end My view (using markaby) for p in @projects li { link_to p.name, :action => :show, :id => p } end - this works correctly on my local machine, i''ve also switched it back to rhtml files and that works correctly also on my hosted server it gives me the "We''re sorry, but something went wrong." message - looking into the production.log file it tells me ActionView::TemplateError (undefined method `each'' for nil:NilClass) so for some reason the @projects isn''t defined if i try debug @projects it returns ''---'' just to see if anything would go through i set a test variable @test ''this is a test string'' and tried to output that. displays nothing and debug gives me the same ''---'' message. The strange thing is inside of an Admin controller I have a list_projects method that mirrors the index method of the Projects controller and it''s views work exactly as they should. So the same for loop above works correctly. Anyone have any idea what''s going on here, I can''t figure out why it''s affecting one controller only and I haven''t been able to find anything that might point me in the right direction - so any help would be much appreciated!!! thanks in advance for any help, pointers, info! Jon --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Arshak Navruzyan
2008-Mar-24 02:23 UTC
Re: Views losing values of Controller instance variables.
Jon, Not sure why this might be happening but whenever it''s happened to me, I just put something like: @projects = [] inside the initialize method and it goes away. Arshak jonsteenbergen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Since moving my app from local to my host (and moving from development > to production) I''ve run into some very odd issues. I''ve searched > around for the past day or so and can''t find anything to answer my > query! So I''m hoping someone else has run into this. > > My instance variables are losing their values when trying to display > them in a view. Sometimes. > > I''ve got a projects section > > The index method in the controller looks like > > def index > @projects = Project.find(:all) > @test = ''test'' > end > > My view (using markaby) > > for p in @projects > li { link_to p.name, :action => :show, :id => p } > end > > - this works correctly on my local machine, i''ve also switched it back > to rhtml files and that works correctly also > > on my hosted server it gives me the "We''re sorry, but something went > wrong." message - looking into the production.log file it tells me > > ActionView::TemplateError (undefined method `each'' for nil:NilClass) > > so for some reason the @projects isn''t defined > if i try debug @projects it returns ''---'' > > just to see if anything would go through i set a test variable @test > ''this is a test string'' > and tried to output that. displays nothing and debug gives me the > same ''---'' message. > > The strange thing is inside of an Admin controller I have a > list_projects method that mirrors the index method of the Projects > controller and it''s views work exactly as they should. So the same > for loop above works correctly. > > Anyone have any idea what''s going on here, I can''t figure out why it''s > affecting one controller only and I haven''t been able to find anything > that might point me in the right direction - so any help would be much > appreciated!!! > > thanks in advance for any help, pointers, info! > Jon-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---