I am attempting to investigate the object state during a login process. I need instruction in the correct technique to emulate filling out an html form and submitting it within the rails console. Given a login form at /user_session/new with fields :username and :password and a submit button. $ script/console ...>> app.new_user_session_path=> "/user_session/new">> @params = { :password => ''mypassword'', :username => ''myuser'' }=> {:password=>"mypassword", :username=>"myuser"} Now, how do I submit this to the create action of the user_sessions_controller? -- Posted via http://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 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 will be easier to debug your app to find out the internal behavior of your objects. http://www.datanoise.com/ruby-debug Daniel On Dec 16, 10:25 am, James Byrne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am attempting to investigate the object state during a login process. > I need instruction in the correct technique to emulate filling out an > html form and submitting it within the rails console. > > Given a login form at /user_session/new with fields :username and > :password and a submit button. > > $ script/console > ...>> app.new_user_session_path > > => "/user_session/new">> @params = { :password => ''mypassword'', :username => ''myuser'' } > > => {:password=>"mypassword", :username=>"myuser"} > > Now, how do I submit this to the create action of the > user_sessions_controller? > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
Daniel wrote:> It will be easier to debug your app to find out the internal behavior > of your objects. > > http://www.datanoise.com/ruby-debug > > DanielPerhaps. But I would still like to know how to get this to work through the console. I have found a few leads on the web, such as : http://snippets.dzone.com/posts/show/600. But, I am afraid that this example does not make a lot of sense to me and appears at first blush to be a bit overwrought. I think that my main problem at this point is my lack of familiarity with some basic Ruby syntax pertaining to hashes or how to construct an http request with form data. If I do this: $ script/console>> app.new_user_session_path=> "/user_session/new That seems correct. Next I need to fill in the form params which are nested in a hash called user_session. This is where I believe that I am going off the rails (pardon the pun). The user_session hash is accessed in the create method of the user_sessions_controller thus: @user_session = UserSession.new(params[:user_session]) :user_session contains three elements, :password, :username, and :remember_me. So I tried this:>> @params = { :user_session => { :password => ''mypass'', :username => ''myname'', :remember_me => ''0'' } }=> {:user_session=>{:remember_me=>"0", :password=>"mypass", :username=>"myname"}} Which also seem ok to me, given I believe that it is @params that I use to pass the form data back. If I misapprehend that, admittedly a strong possibility, then the failure that follows is expected. Then I do this:>> app.post app.user_session_path==> 200 But, the response code only refers to the re-rendered input page which has these errors:>> app.response=> ... <div class=\"errorExplanation\" id=\"errorExplanation\"> <h2>2 errors prohibited this user session from being saved</h2> <p>There were problems with the following fields:</p> <ul> <li>Username can not be blank</li> <li>Password can not be blank</li> </ul> </div> ... Evidently I am not getting the form data to the controller. So, if some kind soul would care to demonstrate to me how this is accomplished within the console then I will be most grateful. Regards, -- Posted via http://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 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 -~----------~----~----~----~------~----~------~--~---
James Byrne wrote:> > Evidently I am not getting the form data to the controller. So, if some > kind soul would care to demonstrate to me how this is accomplished > within the console then I will be most grateful. >I figured it out. $ script/console>> app.new_user_session_path=> "/user_session/new">> @params = { :user_session => { :password => ''mypass'', :username => ''myname'', :remember_me => ''0'' } }=> {:user_session=>{:remember_me=>"0", :password=>"mypass", :username=>"myname"}>> app.post app.user_session_path @params=> 200 Ta Daa... we''re in. -- Posted via http://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 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 -~----------~----~----~----~------~----~------~--~---
James Byrne wrote: s/b>>> app.post app.user_session_path @params > => 302 >Got to watch where I am snipping from... -- Posted via http://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 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 -~----------~----~----~----~------~----~------~--~---
On Dec 16, 2008, at 11:43 AM, James Byrne wrote:> > Perhaps. But I would still like to know how to get this to work > through > the console. I have found a few leads on the web, such as : > http://snippets.dzone.com/posts/show/600. But, I am afraid that this > example does not make a lot of sense to me and appears at first > blush to > be a bit overwrought.I think you''d be better off creating a second way to log in where you can simply pass normal parameters from the console. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Steven Budrys wrote:> > I think you''d be better off creating a second way to log in where you > can simply pass normal parameters from the console.However, that was my problem to begin with, not knowing how to pass parameters from the console. -- Posted via http://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 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 -~----------~----~----~----~------~----~------~--~---
On Dec 16, 2008, at 12:21 PM, James Byrne wrote:> > Steven Budrys wrote: > >> >> I think you''d be better off creating a second way to log in where you >> can simply pass normal parameters from the console. > > However, that was my problem to begin with, not knowing how to pass > parameters from the console.Sorry, I should have been more clear. I meant create a new method that took parameters so that you could call it simply by something like MyController.console_login(name, password) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
James, You can use Mechanize for this sort of things: http://github.com/tenderlove/mechanize/tree/master Cheers, Sazima On Dec 16, 1:25 pm, James Byrne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am attempting to investigate the object state during a login process. > I need instruction in the correct technique to emulate filling out an > html form and submitting it within the rails console. > > Given a login form at /user_session/new with fields :username and > :password and a submit button. > > $ script/console > ...>> app.new_user_session_path > > => "/user_session/new">> @params = { :password => ''mypassword'', :username => ''myuser'' } > > => {:password=>"mypassword", :username=>"myuser"} > > Now, how do I submit this to the create action of the > user_sessions_controller? > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---