Sunday, January 8, 2012

Rhomobile Ajax Calls using JQuery Mobile

Note: This will only work on IPhone,Android and Blackberry(version 6 and above) 

There is common scenario to use Ajax with Rhodes but I was not able to find good source to use them so thought of blogging it. I will be using Jquery Mobile framework which is by default with Rhodes.

In this example I will load some text inside a div on clicking of a button.

Step 1.) Create a div and button on a page
<input type= "button" id="some-button"/ name="button" value="Load Value By Ajax">
      <div id= "some-div">
      </div>


Step 2.) Create a Javascript 

Step 3.) Create a action ajax_method in controller
def ajax_method
    @some_value = "Its all about ruby ---" +@params['some_variable']
    render :action => :ajax_method, :layout => false, :use_layout_on_ajax => false
  end

Step 4.) Create a ajax_method.erb file
<i><b><%= @some_value %></b></i>

It is just a very basic example you can do many more things like error handling, adding loading image etc.



Tuesday, December 27, 2011

Refreshing the column in rails


It may be possible that your database is shared with multiple applications and you data are frequently changing. You can manually refresh the object by:

stock = Stock.find_all
loop do
puts “price = #{price}”
sleep 60
stock.reload
end


Monday, December 19, 2011

Rails Observers vs Callbacks


Rails Callback

Callbacks are methods that get called at certain moments of an object’s life cycle. That means that it can be called when an object is created, saved, updated, deleted, validated, or loaded from the database.

A callback is more short lived. And you pass it into a function to be called once. 


Rails Observers

Observer is similer to Callback but it is used when method is not directly related to object lifecycle. The other difference is an observer lives longer and it can be attached/detached at any time. There can be many observers for the same thing and they can have different lifetimes. 
The best example of Observer is that it could be “send registration confirmation emails” As we can argued that a User model should not include code to send registration confirmation emails so we will create observer for this.



Thursday, November 24, 2011

Rhodes Iphone Build using Xcode


In this post we will create Rhodes build from Xcode. Though we can do this by rake run:iphone for development and rake run:iphone:production for Production but for better understanding and advance configuration we can do the same with Xcode. 

To start quickly,  these are the prerequisite:
  •        Valid Provision Profile should be installed.
  •        Valid Certification should be installed.

For getting these Certification login to Apple Development Center and navigate to iOS Provisioning Portal.

Now to get started follow these steps:
  •    Go to your project folder from Terminal and type:          

             $rake switch_app

The switch_app command changes the rhobuild.yml in the Rhodes source code folder to point to your application, as in the following example for a Rhodes application named Store in the user’s home folder:

env:   
    app: /Users/Name_Of_User/Application_name
  
  • Now run the following command to tell Rhodes to set up the Xcode environment for your Rhodes application:

          $ rake build:iphone:setup_xcode_project

  •    Open rrhorunner.xcodeproj project. This will open your application in Xcode. You can find this project in Gems folder of ruby -> Rhodes-> Platform-> iphone. After opening the project we can see rhorunner project is open in Xcode.


  • To run the application select rhorunner project and then select where you want to run the application. If you have connect iOS device it will appear on list for example in given image I have connected my iphone "Abhishek Nalwaya's iPhone"





If we select "Abhishek Nalwaya's iPhone" and click on Run then it will automatically create the build and install the application on the device. To run in the simulator you can select from the list. 

Debugging Notes: 
  • Make sure you have register the device to appstore for testing.
  • Make sure you have selected correct Code Signing 


  • If you want to restore the XCode use following command:

              $rake build:iphone:restore_xcode_project


If you face any issue feel free to comment on this post.


Monday, October 10, 2011

Motorola Solutions acquires Rhomobile


It is officially announced yesterday that Motorola Solutions has acquires Rhomobile. So this ruby based Mobile Framework is now part of  Motorola Solution. Few week back it was announced that HTML5 based Mobile Framework Phonegap is acquire by Adobe.  So is it Mobile/HTML5 buzz?
Motorola  announced the availability of Motorola RhoElements, a state-of-the-art web-based application framework. It is designed to allow businesses to quickly and cost-effectively develop and deploy web-based applications on existing Motorola Windows Embedded Handheld (formerly known as Windows Mobile) and Windows Embedded Compact (Win-CE) mobile computers as well as Motorola’s recently announced ET1 Android-based enterprise tablet.

These are the key notes of acquisition:
  • All Rhomobile products will continue to be sold and supported globally.  
  • Rhodes will continue to be available open source under the MIT License.
  • They are committed to supporting the Rhomobile community and continuing the open source heritage of Rhodes
  • They also announced their updated Windows Mobile focused mobile browser  now called RhoElements. 
  • Motorola Solutions will provide the scale, resources, industry knowledge, and broader base of partners and channels to accelerate universal adoption of Rho technology



Reference :
http://mediacenter.motorolasolutions.com/Press-Releases/Motorola-Solutions-Offers-Industry-s-First-Framework-for-Developing-HTML5-Applications-on-Windows-Embedded-Handheld-and-Windows-CE-Devices-3741.aspx

http://www.marketwatch.com/story/motorola-solutions-offers-industrys-first-framework-for-developing-html5-applications-on-windows-embedded-handheldtm-and-windows-cetm-devices-2011-10-10

http://techcrunch.com/2011/10/10/motorola-launches-rhoelements-an-html5-framework-for-building-mobile-apps-for-enterprise/

Thursday, September 22, 2011

git branching

There is very nice example given by Satish Talim on git Branch on Google +. Though it is basic but I like the example, that's why sharing the link:


Satish Talim - Google+ - The Free, Online Git / GitHub 101 Course ( Link to Day 7 -…:

'via Blog this'

Thursday, September 1, 2011

Rhomobile Ipad Example- You Tube Client

We will create a Rhomobile ipad application which will search youtube videos and will playback this videos. It is just an example and our purpose is to explore Rhomobile AsyncHttp methods. We will connect to You tube search API. 


Step 1.) Create Rhodes application :
              rhogen app youtube_client
   
Step 2.)  Go to application directery:
              cd youtube_client/

Step 3.)  Create a controller Youtube

Step 4.) Create action search and search_result in youtube_controller.rb



   def search

   end

    def search_result
        you_tube_url = "http://gdata.youtube.com/feeds/api/videos?q=" + @params['name'] + "&max-results=5&v=2&alt=jsonc"
        @youtubes= Rho::AsyncHttp.get(
                                       :url => you_tube_url
                                       )["body"]["data"]["items"]
    end

 We are using AsyncHttp to call You Tube search API. And @params['name'] contain the search term.

5.) Create search.erb 


<div data-role="page">


  <div data-role="header" data-position="inline">
    <h1>Search You tube</h1>
    
  </div>


  <div data-role="content">
    <form method="POST" action="<%= url_for :action => :search_result %>">    
          <div data-role="fieldcontain">
            <label for="name" class="fieldLabel">Name</label>
            <input type="text" id="youtube[name]" name="name" />
          </div>
      
      <input type="submit" value="Update"/>
    </form>
  </div>


</div>




6.) Create search_result.erb and add following code:


<div data-role="page" data-add-back-btn="false">


  <div data-role="header" data-position="inline">
    <h1>Search result</h1>
  </div>


  <div data-role="content">
    <ul data-role="listview">
      
         <% @youtubes.each do |youtube| %>
        <li>
      <center>
            <span class="title">
<%= youtube["title"] %></span><br>
<iframe width="400" height="400" src="http://www.youtube.com/embed/<%= youtube["id"]%>" frameborder="0" allowfullscreen></iframe></center>
<span class="disclosure_indicator"></span>
      
        </li>
    
    <% end %>      
    </ul>
  </div>


</div>







7.) Link the search.erb to home page(by default it is index.erb in app folder.

8.) If you creating it for ipad add following line in build.yml under iphone.
      emulatortarget: ipad
If you creating this app for iphone or Android you can skip this step.

You can Download this code from : https://github.com/nalwayaabhishek/YouTubeClient