Is there a way that I can get hold of the result of a javascript function call from within a controller? There are a few instances where I want to do this. For example, suppose I would like to know if the page to be rendered is within a frame. Within javascript I can determine if the page is within a frame by evaluating either of the conditions: parent.frames.length != 0 or parent.location && (parent.location != window.location) I don''t know how to do this within Rails, and it would be useful to be able to render different content depending on this state. Besides, for reasons too messy to explain, I use javascript to maintain a much more complicated "state" structure (that reacts to events and such) that is way too transitory to store within the database. I would love to be able to query this state from within my controller. Thanks, Nat -- 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 -~----------~----~----~----~------~----~------~--~---
Rails can only get a hold of information that you send to it, so you''ll need to encode this state information on the query string and have your rails controllers handle it along with the rest of the request params. In the case if your frames example, you''ll need to attach some sort of information on the query string to let it know that you''re loading the action up in a frame. e.g.: <script> frames[0].location = "/controller/action?frame=true"; // or something similar var pairs = []; for (var p in state) pairs.push(escape(p + "=" + state[p]); frames[1].location = "/controller/action?state=" + pairs.join('',''); </script> in your controller, get the state by decoding the junk you encoded: state = params[:state].split('','').map { |s| s.split(''='') }.inject({}) {|h,k| h[k.first] = k.last; h} On Mar 8, 7:18 pm, Nathaniel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Is there a way that I can get hold of the result of a javascript > function call from within a controller? > > There are a few instances where I want to do this. For example, suppose > I would like to know if the page to be rendered is within a frame. > > Within javascript I can determine if the page is within a frame by > evaluating either of the conditions: > > parent.frames.length != 0 > > or > > parent.location && (parent.location != window.location) > > I don''t know how to do this within Rails, and it would be useful to be > able to render different content depending on this state. > > Besides, for reasons too messy to explain, I use javascript to maintain > a much more complicated "state" structure (that reacts to events and > such) that is way too transitory to store within the database. > > I would love to be able to query this state from within my controller. > > Thanks, Nat > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nathaniel wrote:> Is there a way that I can get hold of the result of a javascript > function call from within a controller? > > There are a few instances where I want to do this. For example, suppose > I would like to know if the page to be rendered is within a frame. > > Within javascript I can determine if the page is within a frame by > evaluating either of the conditions: > > parent.frames.length != 0 > > or > > parent.location && (parent.location != window.location) > > I don''t know how to do this within Rails, and it would be useful to be > able to render different content depending on this state. > > Besides, for reasons too messy to explain, I use javascript to maintain > a much more complicated "state" structure (that reacts to events and > such) that is way too transitory to store within the database. > > I would love to be able to query this state from within my controller. > > Thanks, NatHere is suggestion. Create a hidden field on the form and populate the field from java script result. The field will be posted back to the controller as a parameter. Hope this is of help. Vin -- 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 -~----------~----~----~----~------~----~------~--~---