Janna Brossard wrote: > Why would my variable I have in my controller as @channel, set as: > def newchannel > @channel = Channel.find(params[:channel][:id]) > render :action => 'display' > end > > Which occurs when the select box changes, be set to nil in another > method in my controller? It acts as a local variable to the function > newchannel -- but I want it to be available throughout my controller. > How can I achieve this? If I specify it as attr_accessor :channel in > my model, then the select box does not populate. > -Janna B. > > On Jul 2, 11:20�am, Onur Gungor <[email protected]>
hi, I am not sure about this either, maybe I must not answer this :) in fact, I thought twice before posting that answer, but decided that this kind of forums are for discussion and speculation for beginners. we will learn together. anyway I'll answer, as far as I know, controllers are created and discarded for each request, so you have to initialize the variables again. this is the way it is. but, if you *really* want to do this, you can achieve a *similar* effect by using a class global variable i.e. @@myvar but this is a very bad idea, so don't do it. basically, initialize the variable in each controller method. onur -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

