5 Replies Latest reply on Dec 10, 2012 1:25 AM by Dean Parker

    How do we execute a method? (Basic question!)

    Dean Parker



      I am developing in Rho for the first time and have a simple question to help get me started. I have been reading through the documentation and some of the samples however I have not been able to get any to run when I try to re-create them in my own project file. For instance lets take a basic alert box. From reading the sample I have put the following in my controller.rb file:



      require 'rho'

      class AlertController < Rho::RhoController

        @layout = :simplelayout


      def alert_test

          @flash = "DeanTest Alert"

          Alert.show_popup "Test"

          render :action => :index, :back => '/app'





      Then in the index.erb file I reference the code like this:



      <input type="button" onclick="alert_test();" value="Test Alert">


      However, northing happens when that button is taped. I guess there is something else I need to do or set somewhere before the method will run. I don't suppose anyone could point me in the right direction?

        • Re: How do we execute a method? (Basic question!)



          <input type="button" onclick="alert_test();" value="Test Alert">


          The above line will try to search for a method alert_test() in javascript.


          To call controller methods from view use ajax or do a form submit


          <input type="button" onclick="$.get('<%= url_for :action => :alert_test %>');" value="Test Alert">


          Calling controller methods using link


          <a href="<%= url_for(:controller => :Alert,:action => :alert_test) %>">Test Alert</a>


          There are lots of ways available to call controller methods from view.



          1 of 1 people found this helpful
          • Re: How do we execute a method? (Basic question!)



            First of all you need be aware that rhodes app is client-server application. Client part executed by a web view control and server part executed by local HTTP server (it runs inside your app on a device).

            Client part is HTML/JavaScript

            Server part is Ruby

            Both these parts runs separately and asynchronously. Client and server communicate by HTTP protocol (and AJAX as in answer above).

            When controller is executed at server side it generates HTML view from erb template and returns it as HTTP body. HTML view then may do explicit HTTP request to server or made implicit request (without reloading) with AJAX. In both cases ruby controller will be called again.


            You may read more about rhodes app structure by links below:




            Also have a look at rhodes online docs in general:



            Best reqgards,


            1 of 1 people found this helpful