PDA

View Full Version : Integrating Sencha with Ruby on Rails: Views... JSON, HTML?



Jeff Blake
28 Dec 2010, 6:35 PM
Hello everyone,
I'm new to Sencha Touch but already recognize the power of it. Im looking for some structural tips on how I should go about programming the views for my app - as Im new to protocols like JSON.

I have a webapp Im programming in Rails, and there are currently no views implemented besides scaffolds.

I want to use Sencha Touch as my view for both web and mobile. (for web, thoughts? Is this a good idea? I find the kitchen sink pretty awesome and using this framework for both views seems like a time saver and simplifies code)

If this is the case, should I be sending data from rails to the views using JSON? or HTML? I'm having a tough time wrapping my head around executing this.


Thanks, Jeff

tomalex0
28 Dec 2010, 8:19 PM
Hi Jeff,

Sencha Touch mainly focused on Webkit browsers now. So if you are planning to use Sencha Touch App for Web, it will be working only with Safari,Chrome browsers and not with Firefox, Opera even though it supports HTML5.

You better send data as JSON from Server and create Views using Sencha Touch then load Data for each Views using Stores and Models


You can find more details on how to structure files here
http://www.sencha.com/conference/sessions/session.php?sid=322

Jeff Blake
28 Dec 2010, 8:49 PM
That's a good point, I better create separate HTML views in rails.

But are you saying I need to manage sencha in a whole new MVC? That sounds like kind of a headache dealing with two sets of MVCs (web and mobile).

I guess when I think about it, it makes sense. I'm programming my desktop web app version in Rails and simultaneously feeding the desktop view using my rails Model. Then, Im building a new MVC for Sencha, and pulling data via JSON from the Rails Model. Is this correct? Is this a good approach?

For a project that is primarily mobile (if not all mobile) it seems like this way sort of regards the mobile version as a spinoff.

Jeff Blake
29 Dec 2010, 12:53 PM
Another quick point I want to bring up for discussion:

Sencha is clearly a Declarative framework whereas others such as JQmobile, JQTouch, etc are markup based. I can see how easily the latter two could be used to create templates such as *.mobile.erb and stick them into the corresponding rails Views - thus creating a nicely integrated application. (Mobile Fu could be used to direct the rendering: format.mobile {render..)

My question is, can this be done with Sencha? This saves the bloated need of programming separate application controllers in Sencha.

I'm looking for the best way to stitch rails and sencha together. It seems there is very little documentation or discussion about this anywhere on the internet.

antonysastre
16 Feb 2011, 12:19 PM
Jeff, the way I'm doing this while learning Sencha is using the solutions you mention above and sticking the JS in the rendered mobile template directly.

I.e. Using mobile_fu to render *.mobile.erb templates and they just contain:


<script type='text/javascript> Ext.setup({..});</script>

xonmac
22 Feb 2011, 11:06 PM
I would also recommend having a look into Netzke (http://netzke.org), which allows for a modular approach to writing your apps. The support for Sencha Touch is still basic (there's no pre-built components, as in case of Ext JS), but it might be a place to start.