5 Replies Latest reply on Feb 12, 2013 6:37 PM by Mark Nongkhlaw

    Layout is being rendered for callbacks

    Jon Tara

      I've got a weird problem on one particular project only. Using Rhodes 3.5.1.12 and 3.5.1.13 on OSX. I'm wondering if anybody else has noticed this or has a solution? I'd imagine it's something we are doing, rather than a bug in Rhodes, but I can't figure out for the life of me what is going wrong.

       

      The layout is being rendered in the HTTP response to all callbacks. We do not call render, and there are no ERB files whose names correspond to the callback methods.

       

      My understanding of Rhodes layout/template rendering and callbacks is:

       

      - The server gets an HTTP request, and matches up the URL with a controller method. It calls the appropriate controller method.

       

      - In the controller method, if you call render, that determines what is rendered and returned in the HTTP response

       

      - If you do not call render, then Rhodes looks for an .erb file in your controller subdirectory with a name corresponding to the method name.

       

      - If there is no corresponding .erb file, then nothing is rendered.

       

      - A valid HTTP header is always returned. So, "nothing is rendered" really means that a response is sent with HTTP headers and content length of 0.

       

      - In the case of a callback (RhoTimer, AsyncHttp, etc. etc. etc.) Rhodes sends an HTTP request to the server, ultimately causing the corresponding controller method to be called. The HTTP response is ignored.

       

      So, this problem is benign, in that it doesn't cause anything "bad" to happen - except that the layout is needlessly rendered, and inserted in the HTTP response, which will be ignored.

       

      I noticed this only because I had set the log level to 0.

       

      Workaround:

       

      - If the controller only has callbacks, you can add:

       

         layout false

       

      at the top of the Controller class.

       

      - If the controller has a mix of callbacks and pages that you want to render, you need to add:

       

        render :string => '', :layout => false

       

      in each callback method.

       

      I'd rather that Rhodes didn't even put the headers in the response. There is no need for them, right? (Maybe useful if debugging by sending requests from a browser URL bar to test callbacks?)

        • Re: Layout is being rendered for callbacks
          Mark Nongkhlaw

          Jon, can you provide more details to reproduce this. How do you set the log level. Is it in rhoconfig.txt :

           

          MinSeverity  = 0   

           

          How do you check for layout rendering?

           

          Does layout also render for WebView.navigate? I have this callback code snippet in my controller :

           

            def seedScheme  

              Rho::AsyncHttp.get(:url => Rho::RhoConfig.RESTFUL_URL + "scheme_tb.json",

              :headers => {"Content-Type" => "application/json"},

              :callback => (url_for :action => :getScheme_callback))

               

                #render :action => :waiting

              WebView.navigate ( url_for :action => :waiting )

            end

            def waiting

            end

           

          I also have an ERB corresponding to the waiting method. I just wanted to verify whether the layout is also rendered along with waiting.erb

           

          Thanks.

            • Re: Layout is being rendered for callbacks
              Jon Tara

              Yes, just set MinSeverity to 0 and you will see all HTTP responses from the server in the log. (Twice, actually - it's quite confusing...) It will display the HTTP headers and any content in the log.

               

              I didn't notice if it renders for WebView.navigate. IMO, it should not, but of course then it will render in response to the request that the browser subsequently makes.

                • Re: Layout is being rendered for callbacks
                  Mark Nongkhlaw

                  Jon, my RhoStudio rholog.txt is always empty even with MinSeverity set to 0.

                  So I used a local Win32 build to test it. With the code I provided, I fired off the seedScheme method. This was what I got in the log (this was also using WebView.navigate) :

                   

                  T 02/12/2013 13:33:13:000 0000167c  MainWindow.cpp: 928| OnBeforeNavigate2: http://localhost:1886/app/Scheme

                  I 02/12/2013 13:33:13:000 000016a8           HttpServer| Process URI: '/app/Scheme'

                  I 02/12/2013 13:33:13:000 000016a8                  APP| RHO serve: /app/Scheme

                  I 02/12/2013 13:33:13:000 000016a8              RhoRuby| require_compiled: Scheme/scheme_controller

                  I 02/12/2013 13:33:13:000 000016a8                  APP| const_missing: Scheme

                  I 02/12/2013 13:33:13:015 000016a8                  APP| load_model: Scheme

                  I 02/12/2013 13:33:13:015 000016a8              RhoRuby| require_compiled: Scheme/scheme

                  I 02/12/2013 13:33:13:015 000016a8                  APP| model name: Scheme

                  I 02/12/2013 13:33:13:015 000016a8                  APP| model class found

                  I 02/12/2013 13:33:13:015 000016a8                  APP| Scheme : {"property"=>{}}

                  I 02/12/2013 13:33:13:015 000016a8                  APP| init_db_sources

                  I 02/12/2013 13:33:13:015 000016a8                  APP| start_id: 40016

                  I 02/12/2013 13:33:13:015 000016a8                  APP| Migrate schema sources: {}

                  T 02/12/2013 13:33:13:109 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  I 02/12/2013 13:33:14:093 000016a8 RHO SchemeController| Layout file: E:/oasisbb/bin/rho/apps/app/layout_erb.iseq. Content size: 848

                  I 02/12/2013 13:33:14:375 000016a8           HttpServer| Process URI: '/public/css/windows_mobile.css'

                  T 02/12/2013 13:33:14:390 0000167c           MainWindow| OnNavigateComplete2: http://localhost:1886/app/Scheme

                  T 02/12/2013 13:33:14:406 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  T 02/12/2013 13:33:14:406 0000167c           MainWindow| OnDocumentComplete: http://localhost:1886/app/Scheme

                  T 02/12/2013 13:33:16:765 0000167c  MainWindow.cpp: 928| OnBeforeNavigate2: http://localhost:1886/app

                  I 02/12/2013 13:33:16:765 000016a8           HttpServer| Process URI: '/app'

                  I 02/12/2013 13:33:16:781 000016a8           HttpServer| Process URI: '/app/index_erb.iseq'

                  I 02/12/2013 13:33:16:781 000016a8                  APP| RHO serve_index: /app/index_erb.iseq

                  I 02/12/2013 13:33:16:781 000016a8 RHO Rho::RhoController| inst_render_index

                  T 02/12/2013 13:33:16:781 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  I 02/12/2013 13:33:16:781 000016a8 RHO Rho::RhoController| index layout

                  I 02/12/2013 13:33:16:796 000016a8           HttpServer| Process URI: '/public/css/windows_mobile.css'

                  T 02/12/2013 13:33:16:796 0000167c           MainWindow| OnNavigateComplete2: http://localhost:1886/app/index_erb.iseq

                  T 02/12/2013 13:33:16:812 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  T 02/12/2013 13:33:16:812 0000167c           MainWindow| OnDocumentComplete: http://localhost:1886/app/index_erb.iseq

                  T 02/12/2013 13:33:20:781 0000167c  MainWindow.cpp: 928| OnBeforeNavigate2: http://localhost:1886/app/Scheme/seedScheme

                  I 02/12/2013 13:33:20:781 000016a8           HttpServer| Process URI: '/app/Scheme/seedScheme'

                  I 02/12/2013 13:33:20:781 000016a8                  APP| RHO serve: /app/Scheme/seedScheme

                  I 02/12/2013 13:33:20:781 000016a8            AsyncHttp| addCommand: GET

                  T 02/12/2013 13:33:20:781 0000167c  MainWindow.cpp: 928| OnBeforeNavigate2: http://localhost:1886/app/Scheme/waiting

                  I 02/12/2013 13:33:20:796 0000144c            AsyncHttp| Starting main routine...

                  I 02/12/2013 13:33:20:796 0000144c                  Net| Method: GET;Url: http://10.179.22.5:3000/scheme_tb.json

                  T 02/12/2013 13:33:20:906 0000144c                  Net| x-ua-compatible:IE=Edge

                  T 02/12/2013 13:33:20:906 0000144c                  Net| etag:"ba3ef1f313a7333680991c536c419ac1"

                  T 02/12/2013 13:33:20:906 0000144c                  Net| connection:Keep-Alive

                  T 02/12/2013 13:33:20:906 0000144c                  Net| content-type:application/json; charset=utf-8

                  T 02/12/2013 13:33:20:906 0000144c                  Net| date:Tue, 12 Feb 2013 08:03:20 GMT

                  T 02/12/2013 13:33:20:906 0000144c                  Net| server:WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10)

                  T 02/12/2013 13:33:20:906 0000144c                  Net| x-request-id:6bb3921aafc2d1fb03d9e7b86239f6d5

                  T 02/12/2013 13:33:20:906 0000144c                  Net| x-runtime:0.109375

                  T 02/12/2013 13:33:20:906 0000144c                  Net| content-length:23492

                  T 02/12/2013 13:33:20:906 0000144c                  Net| cache-control:max-age=0, private, must-revalidate

                  I 02/12/2013 13:33:20:906 0000144c                  Net| Method: POST;Url: http://127.0.0.1:1886/app/Scheme/getScheme_callback

                  I 02/12/2013 13:33:20:921 000016a8 RHO SchemeController| Layout file: E:/oasisbb/bin/rho/apps/app/layout_erb.iseq. Content size: 484

                  E 02/12/2013 13:33:20:921 000016a8           HttpServer| Can not send response data: 10054

                  I 02/12/2013 13:33:20:921 000016a8           HttpServer| Process URI: '/app/Scheme/waiting'

                  I 02/12/2013 13:33:20:921 000016a8                  APP| RHO serve: /app/Scheme/waiting

                  I 02/12/2013 13:33:20:968 000016a8 RHO SchemeController| Layout file: E:/oasisbb/bin/rho/apps/app/layout_erb.iseq. Content size: 667

                  I 02/12/2013 13:33:20:968 000016a8           HttpServer| Process URI: '/app/Scheme/getScheme_callback'

                  I 02/12/2013 13:33:20:968 000016a8                  APP| RHO serve: /app/Scheme/getScheme_callback

                  I 02/12/2013 13:33:20:968 000016a8                  APP| Params: {"rho_callback"=>"1", "status"=>"ok", "http_error"=>"200", "headers"=>{"cache-control"=>"max-age=0, private, must-revalidate", "connection"=>"Keep-Alive", "content-length"=>"23492", "content-type"=>"application/json; charset=utf-8", "date"=>"Tue, 12 Feb 2013 08:03:20 GMT", "etag"=>"\"ba3ef1f313a7333680991c536c419ac1\"", "server"=>"WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10)", "x-request-id"=>"6bb3921aafc2d1fb03d9e7b86239f6d5", "x-runtime"=>"0.109375", "x-ua-compatible"=>"IE=Edge"}, "__rho_object"=>{"body"=>"0"}}

                  T 02/12/2013 13:33:20:984 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  T 02/12/2013 13:33:20:984 0000167c           MainWindow| OnNavigateComplete2: http://localhost:1886/app/Scheme/waiting

                  T 02/12/2013 13:33:21:093 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  I 02/12/2013 13:33:23:953 0000167c            RhodesApp| callAppActiveCallback

                  I 02/12/2013 13:33:23:953 0000167c         AppCallbacks| addCommand: APP-DEACTIVATED

                  I 02/12/2013 13:33:23:953 0000167c                  Net| Method: GET;Url: http://127.0.0.1:1886/system/deactivateapp

                  I 02/12/2013 13:33:23:953 000016a0         AppCallbacks| process command: APP-DEACTIVATED

                  I 02/12/2013 13:33:23:953 000016a0         AppCallbacks| ThreadQueue blocked for 4294967295 seconds...

                  I 02/12/2013 13:33:49:484 0000144c            AsyncHttp| ThreadQueue blocked for 4294967295 seconds...

                  I 02/12/2013 13:33:49:484 000016a8           HttpServer| Process URI: '/public/css/windows_mobile.css'

                  I 02/12/2013 13:33:49:500 000016a8           HttpServer| Process URI: '/system/deactivateapp'

                  I 02/12/2013 13:33:49:500 0000167c            RhodesApp| callAppActiveCallback

                  I 02/12/2013 13:33:49:500 0000167c         AppCallbacks| addCommand: APP-ACTIVATED

                  I 02/12/2013 13:33:49:500 000016a0         AppCallbacks| process command: APP-ACTIVATED

                  I 02/12/2013 13:33:49:500 000016a0                  Net| Method: GET;Url: http://127.0.0.1:1886/system/activateapp

                  I 02/12/2013 13:33:49:500 000016a8           HttpServer| Process URI: '/system/activateapp'

                  I 02/12/2013 13:33:49:515 000016a0         AppCallbacks| ThreadQueue blocked for 4294967295 seconds...

                  T 02/12/2013 13:33:49:593 0000167c           MainWindow| OnDocumentComplete: http://localhost:1886/app/Scheme/waiting

                  T 02/12/2013 13:33:49:593 0000167c  MainWindow.cpp: 928| OnBeforeNavigate2: http://localhost:1886/app/Scheme/show_result

                  I 02/12/2013 13:33:49:593 000016a8           HttpServer| Process URI: '/app/Scheme/show_result'

                  I 02/12/2013 13:33:49:593 000016a8                  APP| RHO serve: /app/Scheme/show_result

                  I 02/12/2013 13:33:49:625 000016a8 RHO SchemeController| Layout file: E:/oasisbb/bin/rho/apps/app/layout_erb.iseq. Content size: 634

                  T 02/12/2013 13:33:49:625 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  I 02/12/2013 13:33:49:625 000016a8           HttpServer| Process URI: '/public/css/windows_mobile.css'

                  T 02/12/2013 13:33:49:625 0000167c           MainWindow| OnNavigateComplete2: http://localhost:1886/app/Scheme/show_result

                  T 02/12/2013 13:33:49:640 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  T 02/12/2013 13:33:49:656 0000167c           MainWindow| OnDocumentComplete: http://localhost:1886/app/Scheme/show_result

                  T 02/12/2013 13:33:51:734 0000167c  MainWindow.cpp: 928| OnBeforeNavigate2: http://localhost:1886/app/Scheme

                  I 02/12/2013 13:33:51:734 000016a8           HttpServer| Process URI: '/app/Scheme'

                  T 02/12/2013 13:33:51:734 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  I 02/12/2013 13:33:51:734 000016a8                  APP| RHO serve: /app/Scheme

                  I 02/12/2013 13:33:51:765 000016a8 RHO SchemeController| Layout file: E:/oasisbb/bin/rho/apps/app/layout_erb.iseq. Content size: 22212

                  I 02/12/2013 13:33:52:140 000016a8           HttpServer| Process URI: '/public/css/windows_mobile.css'

                  T 02/12/2013 13:33:52:140 0000167c           MainWindow| OnNavigateComplete2: http://localhost:1886/app/Scheme

                  T 02/12/2013 13:33:52:171 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  T 02/12/2013 13:33:52:171 0000167c           MainWindow| OnDocumentComplete: http://localhost:1886/app/Scheme

                  T 02/12/2013 13:34:00:234 0000167c  MainWindow.cpp: 928| OnBeforeNavigate2: http://localhost:1886/app

                  I 02/12/2013 13:34:00:234 000016a8           HttpServer| Process URI: '/app'

                  I 02/12/2013 13:34:00:234 000016a8           HttpServer| Process URI: '/app/index_erb.iseq'

                  I 02/12/2013 13:34:00:234 000016a8                  APP| RHO serve_index: /app/index_erb.iseq

                  I 02/12/2013 13:34:00:234 000016a8 RHO Rho::RhoController| inst_render_index

                  I 02/12/2013 13:34:00:250 000016a8 RHO Rho::RhoController| index layout

                  I 02/12/2013 13:34:00:265 000016a8           HttpServer| Process URI: '/public/css/windows_mobile.css'

                  T 02/12/2013 13:34:00:265 0000167c           MainWindow| OnNavigateComplete2: http://localhost:1886/app/index_erb.iseq

                  T 02/12/2013 13:34:00:281 0000167c           MainWindow| OnBrowserTitleChange: OASIS Mobile

                  T 02/12/2013 13:34:00:281 0000167c           MainWindow| OnDocumentComplete: http://localhost:1886/app/index_erb.iseq

                   

                  <snip>

                   

                  Can you tell from above, whether the layout is loaded even with WebView.navigate?

                    • Re: Layout is being rendered for callbacks
                      Jon Tara

                      It doesn't look like you have your MinSeverity set to 0, because if you did you would be getting a LOT more log than that!

                       

                      Here's an example. The Content-Length should be 0. (IMO). And it is on a different application. Haven't figured out why this one misbehaves this way.

                       

                      As you can see it's rendering the layout and sending it in the response to the geolocation callback. It's not needed - the geolocation callback isn't expecting content in the response. This is happening with all of our callbacks.

                       

                      (I truncated the log below, not showing the entire response.)

                       

                      T 02/12/2013 00:35:20:402 b04eb000      GeoLocation| Set geo view notification callback: (null), (null)
                      T 02/12/2013 00:35:20:402 b04eb000          RhoRuby| HTTP/1.1 200 OK

                      Date: Tue, 12 Feb 2013 00:35:20 GMT

                      Content-Type: text/html; charset=utf-8

                      Content-Length: 1366

                      Connection: close

                      Pragma: no-cache

                      Cache-Control: must-revalidate

                      Cache-Control: no-cache

                      Cache-Control: no-store

                      Expires: 0

                       

                       

                      <!DOCTYPE html>

                      <html lang="en" class=" is-apple" >

                      <head>


                      <meta charset="utf-8" />


                       

                         
                      <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />

                       

                      <link rel="stylesheet" href="/public/css/font-awesome.min.css" />

                      <link rel="stylesheet" href="/public/jqmobile/jquery.mobile-1.2.0.ems.css" />

                      <link rel="stylesheet" href="/public/jqmobile/jquery.mobile.simpledialog2.min.css" />

                       


                      <link rel="stylesheet" href="/public/css/jqmobile-overrides.css"  />

                      <link rel="stylesheet" id="two_col_css_link" href="/public/css/layout_2_column.css" media="all and (min-width: 448px)"/>

                      <script src="/public/jquery/jquery-1.8.2.min.js"></script>

                      <script src="/public/jqmobile/jquery.mobile.custom.js"></script>

                      <script src="/public/jqmobile/jquery.mobile-1.2.0.min.js"></script>

                      <script src="/public/jqmobile/jquery.mobile.simpledialog2.min.js"></script>

                      <script src="/public/js/jqmobile-patch.js"></script>

                       

                           
                      <script src="/public/js/clearForm.js"></script>

                      <script src="/app/layout.js"></script>