I feel awful asking such a basic question, but here it goes.... I have a controller, "NewsController". The user enters and the "list" action is called and I populate an instance variable "@news" which contains all the elements I''d like to display using a form. The user then changes something and the "update" action is called. Is "@news" still in scope? When is "@news" out of scope and thus destroyed? -- Posted via http://www.ruby-forum.com/.
On 5/8/06, Joe Cairns <joe.cairns@gmail.com> wrote:> I feel awful asking such a basic question, but here it goes.... > > I have a controller, "NewsController". > > The user enters and the "list" action is called and I populate an > instance variable "@news" which contains all the elements I''d like to > display using a form. > > The user then changes something and the "update" action is called. > > Is "@news" still in scope? When is "@news" out of scope and thus > destroyed?If I understand you correctly, you have a user going to a "list" page to see all the news and then deciding to click a link to update a news item on that list? The @news item is only good from when it''s created in the controller until the view has been completely rendered. So when the next action (update) is called, it''s no longer around. Instead you''ll need to create it again, or you could pass some relevant information to the update action (if you only want it to find which news item the user wants to update, you could pass that item''s ID to the update action). I hope I''m making any sense here, otherwise I''m sure someone else will come in and clearify it for you. :) Mathias.
Mathias Wittlock wrote:> On 5/8/06, Joe Cairns <joe.cairns@gmail.com> wrote: > If I understand you correctly, you have a user going to a "list" page > to see all the news and then deciding to click a link to update a news > item on that list? The @news item is only good from when it''s created > in the controller until the view has been completely rendered. So when > the next action (update) is called, it''s no longer around. Instead > you''ll need to create it again, or you could pass some relevant > information to the update action (if you only want it to find which > news item the user wants to update, you could pass that item''s ID to > the update action). > > I hope I''m making any sense here, otherwise I''m sure someone else will > come in and clearify it for you. :) > > Mathias.Thanks Mathias, that''s perfectly clear (at least to me! :D)! -- Posted via http://www.ruby-forum.com/.