I have the usual methods in a RESTful implementation: index, new
In the index method I have a variable @new_link which is not nil . At
the end of the index method, I tested the value with logger.info
@new_link.inspect to make sure. And the log output shows that
@new_link is in fact not nill.
Within index.html which is displayed by the index method, I include a
link through new_link_path to call the new method to display a form to
create a new link. I want to prefill this form with the value of
@new_link. However, in the scope of the new method, @new_link is
nill. How can this be? I thought that @new_link should have a scope
that covers the entire instance of the class. Are these two methods
operate in 2 different instances?
Thanks.
–
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.
Every time you make a request, ie call a controller action, your rails
application effectively starts from scratch. There’s no persistent
instance data between requests, and the reason for this is obvious:
imagine that you and another person are using the website at the same
time. If objects persisted between requests, how would the server know
which one was yours and which was the other persons?
That’s why almost every action uses params[:id] to load an object from
the db, or uses params from a form to build a new object.
One seeming exception to this is the session, but even this doesn’t
persist - it uses cookies to get a session key which is used to reload
the session data from the sessions table in the database.
Max,
Thank you for the insightful answer. Following your answer, I have
successfully accomplished my goal by passing value through the session
variable.
Happy New Year.
Vincent.
On Dec 30, 4:48 am, Max W. [email protected] wrote:
One seeming exception to this is the session, but even this doesn’t
persist - it uses cookies to get a session key which is used to reload
the session data from the sessions table in the database.
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 [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.