|
|
|
***SPAM(9.9)*** [Rails] Variable Scope Within a controller
|
Previous Topic
Next Topic
|
| Message |
Author |
Posted: Tue Mar 09, 2010 7:12 pm Subject: ***SPAM(9.9)*** [Rails] Variable Scope Within a controller |
|
|
Ashwin Vel
|
|
I am not currently using database for my application, i am getting the
data from forms, and calling a register api
[ register(username,pwd,email) ].
The only reason i want the username and pwd for "process" is cause
my registration page is a 2 step process. and for each step i have
defined an instance method.
so the first step i register the user, and second step i add some
details . so in the second step i would be calling a function
[ process(username,pwd,Details)]
consider "details" to be a bunch of data in xml format. and i want the
user to enter only details in the second page. so the second page has
to be aware of the username and pwd values.
On Mar 9, 3:58 pm, Frederick Cheung <frederick.che...@gmail.com>
wrote:
| Quote: | On Mar 9, 11:40 pm, Ashwin Vel <velapa...@gmail.com> wrote:
| Quote: | I have a controller for registering an user.
i am not able to use the instance variable @username in "Process". How
do i use them ? and also is it safe to declare usernames and passwords
as global variables.
|
While process and register are two instance methods of your
controller, if your user first goes to the register page and then to
the process page then those are two difference instances of
RegisterController. In a real world deployment they could be handled
by different instances of mongrel/unicorn/passenger/etc, possibly by
different servers. Global variables are also a bad idea. Your choices
for state are pretty much the database, cookies (or the session, but
that sits on top of either cookies or the database) or, to some extent
the html that you spit out
Fred
| Quote: | I am pretty new to ruby on rails. any help would be great.
|
| Quote: | class RegisterController < ApplicationController
|
| Quote: | def register
@username = "User"
@password = "XXXX"
|
| Quote: | def process
# puts "#{@username}" - Doesnt work
|
|
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. |
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|