Can anyone help me out with storing a user''s location to session to be used several times by a user during a login ? I need to create a textbox where the user enters there zip code and then I need to hold that zip code value in session to be used for several queries throughout the user''s time within the site. I also would like to return the user''s actual town and state after the zip is submitted but that is of lesser importance. I think I almost have the controller code but not quite there yet def store_location session [:location] = params[:location] end I think its close although I am new and not totally sure what it is doing. The view code I don''t even know how to start though and I assume it is only the controller and the ''store location'' view that I need to code for? 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The code you have there will do what you expect -- it will store exactly what is on the form submitted to that controller into the session. --Michael On 10/29/07, agilehack <jason.rabolli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Can anyone help me out with storing a user''s location to session to be > used several times by a user during a login ? I need to create a > textbox where the user enters there zip code and then I need to hold > that zip code value in session to be used for several queries > throughout the user''s time within the site. I also would like to > return the user''s actual town and state after the zip is submitted but > that is of lesser importance. I think I almost have the controller > code but not quite there yet > > def store_location > session [:location] = params[:location] > end > > I think its close although I am new and not totally sure what it is > doing. The view code I don''t even know how to start though and I > assume it is only the controller and the ''store location'' view that I > need to code for? > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thank you what does the view look like though - I am weakest on the view side right now, horrible at html,css... On Oct 29, 9:14 am, "Michael Graff" <skan.gryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The code you have there will do what you expect -- it will store > exactly what is on the form submitted to that controller into the > session. > > --Michael > > On 10/29/07, agilehack <jason.rabo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Can anyone help me out with storing a user''s location to session to be > > used several times by a user during a login ? I need to create a > > textbox where the user enters there zip code and then I need to hold > > that zip code value in session to be used for several queries > > throughout the user''s time within the site. I also would like to > > return the user''s actual town and state after the zip is submitted but > > that is of lesser importance. I think I almost have the controller > > code but not quite there yet > > > def store_location > > session [:location] = params[:location] > > end > > > I think its close although I am new and not totally sure what it is > > doing. The view code I don''t even know how to start though and I > > assume it is only the controller and the ''store location'' view that I > > need to code for? > > > Thanks- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''ll paste a simple controller and an associated view (which includes
a form). That might help.
Here is my login form, in app/views/session/new.rhtml
<div class="contentbody">
<% form_tag(:controller => "session", :action =>
"create") do -%>
<div><label for="login">Login</label><br/>
<%= text_field_tag ''login'' %></div>
<div><label
for="password">Password</label><br/>
<%= password_field_tag ''password'' %></div>
<div><%= submit_tag ''Log in'' %></div>
<% end -%>
</div><!-- contentbody -->
And here is the part of my controller which handles it:
class SessionController < ApplicationController
def new
end
def create
if using_open_id?
open_id_authentication(params[:openid_url])
else
password_authentication(params[:login], params[:password])
end
end
def destroy
# self.current_user.forget_me if logged_in?
cookies.delete :auth_token
reset_session
flash[:notice] = "You have been logged out."
redirect_back_or_default ''/''
end
def password_authentication(login, password)
self.current_user = User.authenticate(login, password)
if logged_in?
successful_login
else
failed_login
end
end
def failed_login(message = "Authentication failed.")
flash.now[:error] = message
render :action => ''new''
end
def successful_login
redirect_back_or_default(''/'')
flash[:notice] = "Logged in successfully."
end
end
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
your the best - thanks a ton On Oct 29, 1:47 pm, "Michael Graff" <skan.gryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ll paste a simple controller and an associated view (which includes > a form). That might help. > > Here is my login form, in app/views/session/new.rhtml > > <div class="contentbody"> > <% form_tag(:controller => "session", :action => "create") do -%> > <div><label for="login">Login</label><br/> > <%= text_field_tag ''login'' %></div> > > <div><label for="password">Password</label><br/> > <%= password_field_tag ''password'' %></div> > > <div><%= submit_tag ''Log in'' %></div> > <% end -%> > </div><!-- contentbody --> > > And here is the part of my controller which handles it: > > class SessionController < ApplicationController > def new > end > > def create > if using_open_id? > open_id_authentication(params[:openid_url]) > else > password_authentication(params[:login], params[:password]) > end > end > > def destroy > # self.current_user.forget_me if logged_in? > cookies.delete :auth_token > reset_session > flash[:notice] = "You have been logged out." > redirect_back_or_default ''/'' > end > > def password_authentication(login, password) > self.current_user = User.authenticate(login, password) > if logged_in? > successful_login > else > failed_login > end > end > > def failed_login(message = "Authentication failed.") > flash.now[:error] = message > render :action => ''new'' > end > > def successful_login > redirect_back_or_default(''/'') > flash[:notice] = "Logged in successfully." > end > end--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
OK I think I have the view working, textbox is there here is my method in the controller: def store_location session[:location] = params[:location] redirect_to :action => ''list'' flash[:notice] = "your location is " end so right now you enter a zipcode and it should be storing it to the session, the redirect keeps me on the same page and the flash notice seems to work as well. What I would like to do now is add to that flash notice the actual value I just stored in the hash...something like ...flash[:notice] = "your location is " + [session value] can anyone help with the syntax on this? BTW does that session code look correct for actualy getting the zip stored in the session? I have not been able to verify yet becasue I cant get the flash to return it. here is my view code just in case you need it... <%= start_form_tag :action => ''store_location''%> <%= text_field ''location'', nil %> <%= submit_tag ''your location'' %></form> <%= end_form_tag %> look ok? JR On Oct 29, 2:39 pm, agilehack <jason.rabo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> your the best - thanks a ton > > On Oct 29, 1:47 pm, "Michael Graff" <skan.gryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ll paste a simple controller and an associated view (which includes > > a form). That might help. > > > Here is my login form, in app/views/session/new.rhtml > > > <div class="contentbody"> > > <% form_tag(:controller => "session", :action => "create") do -%> > > <div><label for="login">Login</label><br/> > > <%= text_field_tag ''login'' %></div> > > > <div><label for="password">Password</label><br/> > > <%= password_field_tag ''password'' %></div> > > > <div><%= submit_tag ''Log in'' %></div> > > <% end -%> > > </div><!-- contentbody --> > > > And here is the part of my controller which handles it: > > > class SessionController < ApplicationController > > def new > > end > > > def create > > if using_open_id? > > open_id_authentication(params[:openid_url]) > > else > > password_authentication(params[:login], params[:password]) > > end > > end > > > def destroy > > # self.current_user.forget_me if logged_in? > > cookies.delete :auth_token > > reset_session > > flash[:notice] = "You have been logged out." > > redirect_back_or_default ''/'' > > end > > > def password_authentication(login, password) > > self.current_user = User.authenticate(login, password) > > if logged_in? > > successful_login > > else > > failed_login > > end > > end > > > def failed_login(message = "Authentication failed.") > > flash.now[:error] = message > > render :action => ''new'' > > end > > > def successful_login > > redirect_back_or_default(''/'') > > flash[:notice] = "Logged in successfully." > > end > > end--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
"Your location is #{params[:location]}" would work.
Note that it is subject to XSS attacks if it is displayed to 3rd
parties. You''d need to escape the HTML in it if it was.
--Michael
On 10/29/07, agilehack
<jason.rabolli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> OK I think I have the view working, textbox is there
> here is my method in the controller:
>
> def store_location
> session[:location] = params[:location]
> redirect_to :action => ''list''
> flash[:notice] = "your location is "
> end
>
> so right now you enter a zipcode and it should be storing it to the
> session, the redirect keeps me on the same page and the flash notice
> seems to work as well. What I would like to do now is add to that
> flash notice the actual value I just stored in the hash...something
> like ...flash[:notice] = "your location is " + [session value]
>
> can anyone help with the syntax on this?
>
> BTW does that session code look correct for actualy getting the zip
> stored in the session? I have not been able to verify yet becasue I
> cant get the flash to return it.
>
> here is my view code just in case you need it...
>
> <%= start_form_tag :action => ''store_location''%>
> <%= text_field ''location'', nil %>
> <%= submit_tag ''your location'' %></form>
> <%= end_form_tag %>
>
> look ok?
>
> JR
>
> On Oct 29, 2:39 pm, agilehack
<jason.rabo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > your the best - thanks a ton
> >
> > On Oct 29, 1:47 pm, "Michael Graff"
<skan.gryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > > I''ll paste a simple controller and an associated view
(which includes
> > > a form). That might help.
> >
> > > Here is my login form, in app/views/session/new.rhtml
> >
> > > <div class="contentbody">
> > > <% form_tag(:controller => "session", :action
=> "create") do -%>
> > > <div><label
for="login">Login</label><br/>
> > > <%= text_field_tag ''login'' %></div>
> >
> > > <div><label
for="password">Password</label><br/>
> > > <%= password_field_tag ''password''
%></div>
> >
> > > <div><%= submit_tag ''Log in''
%></div>
> > > <% end -%>
> > > </div><!-- contentbody -->
> >
> > > And here is the part of my controller which handles it:
> >
> > > class SessionController < ApplicationController
> > > def new
> > > end
> >
> > > def create
> > > if using_open_id?
> > > open_id_authentication(params[:openid_url])
> > > else
> > > password_authentication(params[:login], params[:password])
> > > end
> > > end
> >
> > > def destroy
> > > # self.current_user.forget_me if logged_in?
> > > cookies.delete :auth_token
> > > reset_session
> > > flash[:notice] = "You have been logged out."
> > > redirect_back_or_default ''/''
> > > end
> >
> > > def password_authentication(login, password)
> > > self.current_user = User.authenticate(login, password)
> > > if logged_in?
> > > successful_login
> > > else
> > > failed_login
> > > end
> > > end
> >
> > > def failed_login(message = "Authentication failed.")
> > > flash.now[:error] = message
> > > render :action => ''new''
> > > end
> >
> > > def successful_login
> > > redirect_back_or_default(''/'')
> > > flash[:notice] = "Logged in successfully."
> > > end
> > > end
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
it works thanks a ton!!! i had my quotes messed up - still new On Oct 29, 10:51 pm, "Michael Graff" <skan.gryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> "Your location is #{params[:location]}" would work. > > Note that it is subject to XSS attacks if it is displayed to 3rd > parties. You''d need to escape the HTML in it if it was. > > --Michael > > On 10/29/07, agilehack <jason.rabo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > OK I think I have the view working, textbox is there > > here is my method in the controller: > > > def store_location > > session[:location] = params[:location] > > redirect_to :action => ''list'' > > flash[:notice] = "your location is " > > end > > > so right now you enter a zipcode and it should be storing it to the > > session, the redirect keeps me on the same page and the flash notice > > seems to work as well. What I would like to do now is add to that > > flash notice the actual value I just stored in the hash...something > > like ...flash[:notice] = "your location is " + [session value] > > > can anyone help with the syntax on this? > > > BTW does that session code look correct for actualy getting the zip > > stored in the session? I have not been able to verify yet becasue I > > cant get the flash to return it. > > > here is my view code just in case you need it... > > > <%= start_form_tag :action => ''store_location''%> > > <%= text_field ''location'', nil %> > > <%= submit_tag ''your location'' %></form> > > <%= end_form_tag %> > > > look ok? > > > JR > > > On Oct 29, 2:39 pm, agilehack <jason.rabo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > your the best - thanks a ton > > > > On Oct 29, 1:47 pm, "Michael Graff" <skan.gryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''ll paste a simple controller and an associated view (which includes > > > > a form). That might help. > > > > > Here is my login form, in app/views/session/new.rhtml > > > > > <div class="contentbody"> > > > > <% form_tag(:controller => "session", :action => "create") do -%> > > > > <div><label for="login">Login</label><br/> > > > > <%= text_field_tag ''login'' %></div> > > > > > <div><label for="password">Password</label><br/> > > > > <%= password_field_tag ''password'' %></div> > > > > > <div><%= submit_tag ''Log in'' %></div> > > > > <% end -%> > > > > </div><!-- contentbody --> > > > > > And here is the part of my controller which handles it: > > > > > class SessionController < ApplicationController > > > > def new > > > > end > > > > > def create > > > > if using_open_id? > > > > open_id_authentication(params[:openid_url]) > > > > else > > > > password_authentication(params[:login], params[:password]) > > > > end > > > > end > > > > > def destroy > > > > # self.current_user.forget_me if logged_in? > > > > cookies.delete :auth_token > > > > reset_session > > > > flash[:notice] = "You have been logged out." > > > > redirect_back_or_default ''/'' > > > > end > > > > > def password_authentication(login, password) > > > > self.current_user = User.authenticate(login, password) > > > > if logged_in? > > > > successful_login > > > > else > > > > failed_login > > > > end > > > > end > > > > > def failed_login(message = "Authentication failed.") > > > > flash.now[:error] = message > > > > render :action => ''new'' > > > > end > > > > > def successful_login > > > > redirect_back_or_default(''/'') > > > > flash[:notice] = "Logged in successfully." > > > > end > > > > end--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---