good example applications combining rails 3 and sproutcore - ruby-on-rails

I am trying to write a sproutcore frontend for a rails 3.1 application I am making. I have had a look at the sproutcore guides, but I am interested in seeing real examples how to use sproutcore together with rails 3(.1).
I have found two examples, but each is totally different:
A todo-app created using bulk_api: an interesting approach using a specific REST-style to minimise the traffic. But it proposes to place the sproutcore app in app/sproutcore, and is still a bit unclear to me how that actually hooks in completely.
Travis-ci which seems to be a very clean example, rails 3.1, to use sproutcore. It is not yet completely clear to me, but all sproutcore js is cleanly stored inside app/assets/javascript/apps and as far as i can tell, the application.html just loads the js and provides the frame where everything is loaded into.
Do you know any other examples? How do you use sproutcore in your rails app?

The method you describe is the same way that you integrate backbone.js into a rails app, and it seems to work very well
https://github.com/codebrew/backbone-rails
This stores backbone in
app/assets/javascripts/backbone/
app/assets/javascripts/backbone/app/models
app/assets/javascripts/backbone/app/controllers
And then there is a script tag in the view that just initializes backbone
<script type="text/javascript">
$(function() {
// Blog is the app name
window.router = new Blog.Routers.PostsRouter({posts: <%= #posts.to_json.html_safe -%>});
Backbone.history.start();
});
</script>
I imagine a similar process for sproutcore would make sense

I did find a demo-project: sproutcore-on-rails that did manage to make things clearer for me.

Related

Can AngularJS architecture interfere with a framework like Ruby on Rails at some point?

I have a web application that has most of it's logic on ruby on rails, and lately I've been getting good at AngularJS but I'm not a master at it. What I like about angular is that it lets you be very declarative on your javascript code knowing if an element is being referenced on the html unlike jquery. Also it has nice filtering options but that would not be needed cause rails handles that on the server-side. Is AngularJS meant to work as a stand alone framework or it can coexist with server-side frameworks?.
This is more of a discussion question, so not an ideal SO question.
Angular and Rails can happily coexist.
You can use the asset pipeline and load Angular, in the same way that you would any other JS library.
There is a good tutorial here, also, this Railscast is quite handy although it is a bit out of date now.
My advice is to have a crack at it, and then come back to SO and post specific bugs or challenges you are hitting.

Integrating rails & angularjs

I tried Angular, and I liked it. I've began to integrate him into my rails-app, but then appeared some doubts about architecture
Routes. I would like to navigate without refreshing the page, before i used Wiselinks gem, it's easy and cool - just install, patch link_to helper and done. But angular have his own router, and ui-router (which is cool). I want my app to be running at the browser like Opera Mini and IE, but ui-router doesn't have such callbacks as in wiselinks. I wouldn't create mobile site version - the design is adaptive yet. It means, I would use rails routing, but I want to AJAX page refreshing when it can be (progressive enchansement, yep). What do I do?
In many places, the content is rendered by Angular, i.e. a list of posts (by ajaxing json). That fast & cool on desktop, but again old browsers! I need to render it on server for them. Or I haven't?
I'm stuck. Thanks.
This would be best trip to angularjs + rails 4...
This post clear my doubts and now i m very clear about architecture, routes, controllers, model, etc..
http://www.honeybadger.io/blog/2013/12/11/beginners-guide-to-angular-js-rails
I hope this solves your DOUBTs
and to know further about angularjs visit
http://www.angularjs.org
It's not necessary that you have to use angular routing. You can use ng-controller directive to inject controllers in your view.
Angular in general is very fast. I have been using it even in mobile browsers, it works like a charm. True if do heavy $scope manipulation, things might get little slow.
Talking about old browser support, till IE8, you are pretty good, if you follow http://docs.angularjs.org/guide/ie as already mentioned by shaunhusain, but below that I am skeptical.
I wouldnt recommend using wiselinks alongside with angular. We have tried that in a production app and it took us a long time to make this work, there had been so many issues with undead scopes and other artifacts.
Therefore, we have ended up throwing out wiselinks and replacing it with a similar directive written in angular. This way its easier to avoid problems when destroying or compiling dom.

Intergrating Angular JS with rails

I need some guidance to figure out how to incorporate Angular inside rails.
Reason for choosing Rails : I like their opionated approach to do things right. Also migrations, gems are really cool.
Reason for angular : I was researching and looking for framework best suited for SPA. Backbone seem too abstract. I had choice to make between Angular & Ember. I started reading Angular first and it made sense to me. So i never went to read about ember.
Reason for Angular & Rails: I researched and tried using small scale framework like grape, slim ( Yes i use php too ). But i feel need to stick to rails for long term scope of project. And personally i like doing things rails way.
So here is where i need help,
I have rails project in Rails 4.
Sign-in , sign-up everything is created as followed in Michael Hartl tutorial. Have tweaked stuff based on my requirement.
So post-sign-in or post-sign-up steps a view from show action of users controller is rendered.
I figured i'll need different layout files so i created same for outer pages and inner pages, respectively.
I don't know how to proceed i want to make use of the angular templates and routes for my single page app ( which resides post sign-in ). I am flexible if there is another way. I just need a guide how to use angular seemlessly with rails making use of rails controller to handle my rest request and using routing provided by angular to navigate around in SPA.
Hope i am clear. Feel free to edit this.
here is a great railscasts from ryan bates: http://railscasts.com/episodes/405-angularjs
also here is the source for that railscasts you can get ideas from there:
https://github.com/railscasts/405-angularjs
I'm not familiar with SPA, but I have been working on a tutorial for integrating rails and angularjs, which I'm refining over time. It may provide some answers here - in particular I am using the angular routing to provide a single-page app as you describe: http://technpol.wordpress.com/2013/09/03/angularjs-and-rails-tutorial-index/
I would suggest you to not mix angular into your rails app. Keep both of them separate.
So you could either place the whole of your angular app in the public folder of your rails app or keep it completely away from the rails app. This is more like a service oriented architecture, where your rails app serves as a back end serving as an api and the front end(Angular app) consuming that api.
There are many many nice articles the covers how to handle the authentication/authorization
in angularjs with REST APIs.Authentication with AngularJS and a Node.js REST api
Coming to the rails side for building REST API, Grape is a nice choice. Here is a nice series explaining some best practices about grape.
HTH!
I'd suggest taking a look at this tutorial: How to Wire Up Ruby on Rails and AngularJS as a Single-Page Application. I have used it for a few personal projects, so I am sure that it is up to date as of late 2014. If you want to view it in action you can head to http://goodmatches.herokuapp.com, and you can view the repo.
Try half-pipe gem which makes using bower for managing javascripts assets much easier.

Looking for a fully functional Rails application using Backbone.js

Backbone.js website has some examples. But barring the first one others are not open source. I am looking for a fully functional (meaning it just works) Rails application to study. The app does not need to have too many functionalities. I looked at github and all the apps are broken in some ways.
Recently i found https://github.com/malclocke/fulcrum and it seems to be the best Rails/Backbone example but its not mentioned on the backbone website. Its also a very functional pivotal tracker clone.
I have been working on some non open source projects that use a Rails and Backbone.js stack. Both frameworks can be integrated fairly easily. Of course, it depends on how the application is setup and how you configure each framework to control more or less business logic.
To get both frameworks to play with each other:
Make Backbone collections and models for each Rails model
Route resources for each Rails model
Setup the URL property for the Backbone collections and models to work with your rails routes
Use fetch() and save() in Backbone to get and post data with Rails
I wrote a german language noun trainer using RAILS and backbone.js. It was done a long while ago while I was still learning but you can peek at it if you want.
https://github.com/bradphelan/ohmyderdiedas
I've been actively working on Myelin: http://sourceforge.net/projects/myelin/ (funded from a corporate source)
There are some caveats:
This is essentially a first for me with every technology in there... from rails, to backbone / jquery / rspec... you name it... it's new, so take the code with some grains of salt ;)
I didn't use the Backbone routing, and built a very simple 'router' of my own.
You'll need ganglia and rrdtool installed (macports if you're on a mac should work)
You'll need to alter the development config for sure.
The models, are (mostly) straight up backbone, and I use sync often in the controllers so those should be pretty good examples.
The views are a little more chaotic.
If anyone needs help with anything, just drop a line to me on sourceforge.
There's now a gem in development that provides generators, called rails-backbone. It's Open Source and getting better every day. As of today it's up to date with current Rails 3.1 (actually 3.2 now), esp. including Asset Pipeline, which is very relevant to backbone.js.

Anyone developed an App with a Flex UI and Rails backend?

i am looking into the possibilities of doing some work for a client on Flex with a Rails backend.
It ain't rocket science however i was wondering if anyone out there had some experiences with these two AWESOME technologies?
Thanks in advance....
Peter Armstrong has written an excellent book called Flexible Rails, and has also created a Flex/Rails framework called Ruboss. I recommend you check out both of these resources.
I have developed a few application using Flex and Rails. The easiest way is just to use the as3corelib (http://code.google.com/p/as3corelib/) and use standard JSON objects. You can play around with the AMF serializers, but none of them are production ready (they are written in ruby and not C).
The biggest thing you need to make sure of is if you are creating resources from Flex you need to send the authenticity key from flex. I do this by writing a helper to output it to a view:
<script language="Javascript">
function getAuthKey() { return "<%= form_authenticity_token %>"; }
</script>
Then use ExternalInterface to call it inside Flex.
ExternalInterface.call('getAuthKey')

Resources