How to integrate a Rails application with Angular2 in a single application? - ruby-on-rails

I know there are easy ways to get AngularJS working as the front end of a Ruby on Rails application such as the angularjs-rails gem, but I haven't been able to do the same thing with Angular 2. I know I could just make 2 different applications and just have them work together, but I'd rather have them in 1 app so I can just start the one app and it'll all run and do all the testing in one app at one time.

As no "rails-angular2" gem has been released yet, you can do the integration by yourself following this link: http://programming.sereale.fr/20...
It is an example of integration without npm, but if you want to use npm you may still find a few interesting clues.

Related

Where to put code from a preliminary gem in a rails app?

I'm working on a government transparency app. For the app I'm using two different APIs from the sunlight foundation. One already had a good gem wrapper that provided all the functionality I needed. The other didn't, so I wrote the code myself with the plan of packaging it as a gem and using it in my app. The code is done, but needs some refactoring as well some setup to properly turn it into a gem. Unfortunately, I need to finish the app quickly for a demo I'm doing in a couple of days and just want to add the code to my existing app for the moment and then extract it out later to make a gem.
I'm a new programmer(about 3 months), so I'm still getting some of the convention and what not. What I'm not sure is where to put the code in my rails app. Does it go in the model, controller, or do I build a separate helper module. The code for the app is here: https://github.com/gbcosgrove/sunlight-influence. It consists of an API call constructor and then separate files for each category. I'm still in the process of refactoring because I find it easier to just write code that works and then go back and iterate until its clean.
Any insight on where to put this code in an existing rails app not as a gem would be awesome. Thank you so much!!

Ruby on Rails not rendering views when downgrading from version 3 to 2

I am in the middle of putting up my Ruby on Rails app to a live server but have to downgrade from version 3 to 2 because that is all my shared hosting provider supports. I was able to adapt my models, controllers and routes without much problem. The problem I am having is with the views rendering.
I went through the process of creating a default layout for each controller as Rails 2 requires. When I run the app on the server, it starts just fine and the smokescreen index.html is visible but if I delete that and try to see the real app, all I get are broken links and files that are unable to load according to the browser.
I am sure this is an issue due to the downgrade. Any ideas on what I am doing wrong?
Doing a downgrade from Rails 3 to Rails 2 seems to me like a crazy thing to do for many reasons:
1) Rails 4 is already released. You should be looking to upgrade instead of downgrading.
2) There are many hosts out there that offer amazing services and even some free. Heroku is a great place to start if you don't want to manage your own server.
3) Rails 3 was almost a complete rewrite of the way Rails worked. This includes the addition of the Assets Pipeline which is a blessing in terms of development.
With that said, if you're still looking to downgrade, I would try to revert the steps found in many Upgrading Rails 2 to Rails 3 tutorials out there.
They are a bit long and many steps required to put here but a simple google search will yield many great resources. Here's a Railscasts http://railscasts.com/episodes/226-upgrading-to-rails-3-part-2

Rails 3 / PhoneGap: Converting a Rails app into an Phonegap iOS app?

I have a site built on top of Rails. In essence, I want to release a lightweight version of it for the appstore, and I think Phonegap is a good solution w/o writing a full iOS application.
What would be the easiest way to get something like this out of the door? I'm new to PhoneGap and would love if an experience dev could shed some light on how with is done. I feel it would also be a valuable resource for many other Rails devs.
My rails 3 app uses devise for authenication, carrierwave for file processing, amazon S3 for storage, and Heroku for hosting. Can someone give me some basic insight into how all these components are wrapped up and ablwe to be used with PhoneGap?
I'm new to Phonegap too, but I'm exploring the same idea than you and I've found this useful screencast: "PhoneGap + Rails 3 API"
http://vimeo.com/18763953
The idea is that you make an HTML5 client side app that makes calls to a Rails API on the server side.
Here is the code of the screencast demo:
https://github.com/quickleft/kbomb_phonegap_server (Rails API)
https://github.com/quickleft/kbomb_phonegap_client (HTML5 client with
Phonegap).
Hope it helps!
I think it could be relevant to check my phonegap-rails gem gem and my example rails / ember.js App that is exported with Phonegap. It also implements token authentication based on ember-auth and several OAuth strategies on top of Devise.
Currently in de the devel branch: https://github.com/joscas/base_app/tree/devel
Heroku deploy: https://starter-app-staging.herokuapp.com (the desktop version)
The gem exports assets, fixes paths etc. to allow seamless export of single page apps based on a rails backend.
At 37 Signals they rendered their html SERVER SIDE and just created an app wrapper. Here's the article: https://signalvnoise.com/posts/3743-hybrid-sweet-spot-native-navigation-web-content
This is an important difference in most approaches as most will re-develop their front end using a client side framework and it has the potential to save users a bunch of time. The downside is that I've heard rumors you can't get into the iOS app store, but it doesn't seem like they had a problem with it. There's also services like GoNative.io that will wrap your app for you.
A video and code that does something similar to Javi's answer can be found at
Using Phonegap as a native container for a Rails 3 App

Deploying Rails as a desktop application

I just start RoR development for two weeks, It's pretty amazing programming language so far. It's impressing me so much so that I'm start to thinking about change the programming language of my client's project from PHP to RoR. But what I want to know is, is it possible to make a RoR web app looks like a Native App when using it in a local machine. By the term of Native app I mean ..
The user doesn't have to run script/server or rails server every time they starts their machine
Either access it by Web Browser or something else is fine.
Can be running with Window 7 or Window XP
Other recommendation are welcome. (Including, the reason not to use RoR to develop a local application)
I personally don't think there's anything ridiculous with wanting to deploy a Rails app as a desktop application but it's certainly not the easiest thing to do. Heres a list of what you're going to need:
a compiled distributable ruby interpreter
a distributable database
a script to bootstrap the whole thing( preferably that runs on the click of an icon or when system starts)
an installer
optionally:
write a simple shell in qt or java(possibly with the ruby bindings even) that handled starting and stopping the rails app, and provided a webframe for your customer to use instead of the standard web browser.
Here's a tutorial on deploying a rails app as a desktop app, though for debian, that should start you in the right direction. But your best bet for a quick gui application in ruby is shoes.
since rails is framework for web development there is no way to avoid starting rails server to show something on local machine. you might hide the fact that server is being started by running it as service without letting the user know about it but that's only as far as you can get.
so yes, it is possible to bundle your application into a "native app" but i'm afraid it will be extremely fragile as there are too many pieces that need to fit together: ruby itself, database to use, rails and all the other gems. big chance is you will have a gem that needs to be compiled and then you're in trouble.
bottom line: it's not worth it, either host your app or pick a better solution to develop something that runs only locally.
Maybe out of topic, but if you want to make native application, perhaps make native application? I mean, what's the purpose to develop a web application and then host it locally?
At least, you could consider using free hosts, such as heroku. http://your-project-name.heroku.com will grant you a 5mb database and 1 worker. It's free, will save you a lot of troubles and will make it easier for you to deploy newer version to your clients.
Just have them put a bookmark on their desktop if they want to double click to open application.
Maybe I am wrong but you seem to miss the fact that RoR is not a programming language. Ruby is a programming language and RoR is web-development framework. Anyway if you want to develop desktop applications, you can use Ruby with a framework such as Bowline (to keep the MVC spirit).
If you want a Web application, build a Web application. If you want to build a desktop application, try Monkeybars or Appcelerator.
Quite late for my answer but anyway I had the same problem and use the gem ocra to build an exe for windows.
It is also possible to generate a setup to install the program in the register.
It is still necessary to have a server started but the user has just to click on the exe program; A console is opened and give some instructions like 'after the start of the server, open a browser and go to localhost:3000; Ctrl + C to exit when you have finished.
It could be possible to have the server launched as a service but I think my users prefer to know if the program is running or not.
ocra is not really easy to set but eventually it works fine.

Running Rails as an embedded app inside of a gem

I'm trying to understand what exactly the above (in my question's Title) means? This is taken directly from the SpreeCommerce.com project:
If you’re an experienced Rails developer you may be wondering where your app directory is. Spree actually runs as an embedded Rails app inside of your gem. How do you customize things then? We’ll cover that later in extensions.
Source: http://spreecommerce.com/documentation/getting_started.html
Can someone further explain what exactly it means when a Rails app is run "inside of your gem"
With the gem spree, you can install your application and use it. A lot of application need download complete package to install it. When the gem spree, you don't. So it's more easier to install spree on your server.
The phrase you quote is poorly written and not particularly useful. What you should take away is that Spree is structured different from the majority of Rails plugins.
Typical plugin:
your rails app <-- plugin functionality
A Spree app:
spree rails app <-- your site specific code
Typically, most Rails plugins are installed in the vendor/plugins directory of your Rails app. Some additional functionality is added by classes and modules that you can then reference in your code (subclassing a ResourceController, for instance).
Spree does not work in this way. Because, presumably, there is so much configuration code for Spree, each Spree instance creates a separate Rails app -- one that's missing some of the more important parts of a Rails app (such as the app directory). All of your site specific code goes in the vendor/extensions/site directory. This means you don't have to worry about editing any of the Spree-specific code (since it's all in a different directory) and you can more easily put your own code under source control.

Resources