So I just noticed that rails went on faithfully creating new sessions for each API request. I''d like to stop this behavior, but don''t quite know how. I am using edge with REST routes (api.resources). Is there something I can pass from there to turn off sessions for these accessess? I suspect it will take the form of: session :off, :if => something Any ideas? Cheers, Jake -- 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 -~----------~----~----~----~------~----~------~--~---
In your controller, put: session :disabled => true On 11/19/06, Jake Janovetz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > So I just noticed that rails went on faithfully creating new sessions > for each API request. I''d like to stop this behavior, but don''t quite > know how. > > I am using edge with REST routes (api.resources). Is there something I > can pass from there to turn off sessions for these accessess? > > I suspect it will take the form of: > session :off, :if => something > > Any ideas? > > Cheers, > Jake > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Bruno Celeste wrote:> In your controller, put: > > session :disabled => trueThat would disable sessions for ALL requests to the controller. I only want to disable sessions for API communication. With the RESTful stuff, the API and standard HTML rendering are all rolled up into the same controllers and actions, so something else needs to be done. Jake -- 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 -~----------~----~----~----~------~----~------~--~---
I think I found what you want. From the doc: http://api.rubyonrails.org/classes/ActionController/SessionManagement/ClassMethods.html#M000102 See the last example with :if and Proc. params[:format] will give you the requested format, you can probably play with it to disable session. On 11/19/06, Jake Janovetz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Bruno Celeste wrote: > > In your controller, put: > > > > session :disabled => true > > That would disable sessions for ALL requests to the controller. I only > want to disable sessions for API communication. > > With the RESTful stuff, the API and standard HTML rendering are all > rolled up into the same controllers and actions, so something else needs > to be done. > > Jake > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Bruno Celeste wrote:> I think I found what you want. From the doc: > http://api.rubyonrails.org/classes/ActionController/SessionManagement/ClassMethods.html#M000102 > > See the last example with :if and Proc. > params[:format] will give you the requested format, you can probably > play with it to disable session.Yes, I mentioned this in my initial post. I don''t understand, however, what is passed into that Proc. You''re saying I could do: :if Proc.new {|req| req.params[:format] } What class is "req" ? I''d like to look it up to see what method I can use on it. Jake -- 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 -~----------~----~----~----~------~----~------~--~---
Hey Jake, I would assume that the proc just has to return true or false indicating whether or not to create a new session. so something along the lines of session :off, :if => Proc.new {|r| r.parameters[:format] == :api} or something along those lines. HTH On 11/19/06, Jake Janovetz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Bruno Celeste wrote: > > I think I found what you want. From the doc: > > > http://api.rubyonrails.org/classes/ActionController/SessionManagement/ClassMethods.html#M000102 > > > > See the last example with :if and Proc. > > params[:format] will give you the requested format, you can probably > > play with it to disable session. > > Yes, I mentioned this in my initial post. I don''t understand, however, > what is passed into that Proc. > > You''re saying I could do: > :if Proc.new {|req| req.params[:format] } > > What class is "req" ? I''d like to look it up to see what method I can > use on it. > > Jake > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Rohith Ravi wrote:> Hey Jake, > > I would assume that the proc just has to return true or false indicating > whether or not to create a new session. > > so something along the lines of > > session :off, :if => Proc.new {|r| r.parameters[:format] == :api} > > or something along those lines. > > HTHThat seems reasonable, but I''m still stuck on "r". What class is it? Where is it created? How does one put :format into the parameters hash? Can this be done from routes.rb ? Maybe this is incredibly simple, but it''s just not clear to me. -- 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 Nov 20, 2006, at 9:12 AM, Jake Janovetz wrote:> That seems reasonable, but I''m still stuck on "r". What class is it? > Where is it created? How does one put :format into the parameters > hash? > Can this be done from routes.rb ? > > Maybe this is incredibly simple, but it''s just not clear to me.It''s the request object. One of these: http://api.rubyonrails.org/classes/ActionController/ AbstractRequest.html If you''re using the RESTful routes in edge rails, a request of posts/ 1.api will set :format to ''api'' (as in the previous e-mail''s example). The route looks like this: GET /posts/:id.:format/ {:controller=>"posts", :action=>"show"} It all depends on how you want your API to be accessed. It''s up to you. For more session info, see here: http://errtheblog.com/post/24 -- Chris Wanstrath http://errtheblog.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 -~----------~----~----~----~------~----~------~--~---
Chris Wanstrath wrote:> On Nov 20, 2006, at 9:12 AM, Jake Janovetz wrote: > If you''re using the RESTful routes in edge rails, a request of posts/ > 1.api will set :format to ''api'' (as in the previous e-mail''s > example). The route looks like this: > > GET /posts/:id.:format/ > {:controller=>"posts", :action=>"show"}Hm. Ok. Getting closer. For the sake of posterity, I have my API routes setup to authenticate by a token: map.with_options :path_prefix => "/api/:api_token" do |api| api.resources :person api.resources :company ... end So my session disabling stuff is then: session :off, :if => Proc.new {|req| !req.parameters[:api_token].nil?} Thanks for all the help, gents. I think things are working now. Jake -- 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 -~----------~----~----~----~------~----~------~--~---