Noob Question - Variable Scope

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?

On 5/8/06, Joe C. [email protected] wrote:

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. :slight_smile:

Mathias.

Mathias W. wrote:

On 5/8/06, Joe C. [email protected] 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. :slight_smile:

Mathias.

Thanks Mathias, that’s perfectly clear (at least to me! :D)!