Rails API + AngularJS + Websocket-Rails gem - ruby-on-rails

My server is running the websocket-rails gem to handle websockets.
I'm having trouble using websocket-rails with a phonegap project that uses angular because I need to initialize the websocket-rails client in my Angular front end independent of the rails asset pipeline.
Is it possible to load the websocket-rails client separately into an angular project? Or can I use an angular socket directive to manange sockets with websocket-rails?

I managed to get this working.
I translated all the coffeescripts into js with the coffescript CLI tool. Then I added those files to my project then called the methods in the controller per the websocket-rails docs.

This guy has done the same translation. A github repo with the translated files. Hope it can help someone:
https://github.com/karimbutt/websocket-rails-for-js-frameworks

Related

Can you use a Rails Engine with a JS Framework like Vue

I want to do a project with https://github.com/projectblacklight/blacklight
Can I use it as a Rails API with a Vue frontend?
It is a Rails Engine that returns JSON but it is traditionally used in a Rails app as a Plugin / Gem (really it's an engine which is similar).
https://github.com/projectblacklight/blacklight/wiki
Every Blacklight search provides JSON, RSS, and Atom Responses of search results
I am researching this and so far I think the answer is yes.
Jason Coyne from Stanford built an App using Ember with Blacklight
Here are some more discussions around the question.
+ https://github.com/projectblacklight/blacklight/wiki/JSON-API
+ https://github.com/projectblacklight/blacklight/pull/588
+ https://groups.google.com/forum/#!topic/blacklight-development/TIYCjemfp3A
There is not a lot of documentation about this that I can find.
blacklight-vue is an engine made explicitly for this purpose. blacklight-vue-demo is a sample build with this engine. The generic answer for building any Ruby on Rails application with Vue is to use the Webpacker gem.

How to use react ecosystem with rails 3.2?

I just want to share with you an uncomfortable situation that I'm having right now and ask you for advice. It turns out that I'm developing a kind of old project by using rails 3.2 and ruby 2.0. Until now, as usual I've been creating the view layer with haml markup language. Recently I was assigned to implement a new set of UI requirements that seems to be a little complicated. So I was wondering if I could use the react library to do that. I'm using the react-rails gem to facilitate the integration and it works fine. But the problem comes in when I try to use a third party library like react-dropzone or react-modal or whatever react library. I have not been able to get it to work neither using rails-assets gems nor downloading directly the /dist files and require them with sprockets. Some of the errors that I get are:
typeError: undefined is not an object (evaluating 'webpack_require(3).unstable_renderSubtreeIntoContainer')
Can not find module 'react'
I don't know if I can easily setup a webpack server to compile these react libraries and then can be used along with react-rails and the specific version of rails 3.2. I've searched about the subject and I found the webpacker gem but it requires at least rails 4.2. I appreciate any comment or observation about what should I do.
I've finally solved my problem by using react_on_rails gem which allows an easy integration of React + Webpack + Rails, and also includes the server side rendering option.

react router server side rendering with rails

I am using React Js with rails 5.0
Important Gems are
gem 'rails', '~> 5.0.2'
gem 'react-rails'
gem 'react-router-rails'
gem 'slim-rails'
my layout and page template is in slim and I am using coffee everywhere.
I am facing lots of problem when I am using react router.
List of questions are:
I want to get a clean approach like angular where I can use module + controller + views in react. Can be it possible?
As now I am using react-router but the thing is that when it send request to the server so request comes to my action controller, action view and layout but does not load react components.
I am not able to use new packages like react-validation( https://www.npmjs.com/package/react-validation). How can I use react packages.
In react routing I want to send request on server and then it loads components which is exist on that action view.
Suggest me for the best approach of using react js + rails
Let's start with the basics, and I apologize if it sounds too basic.
'React' can be viewed as the Facebook JavaScript libraries, the set of JavaScript libraries put out by a community of React users, or the base design philosophy of nested component rendering and tag based caching.
JavaScript is inherent to React libraries, but not to its philosophy.
React on Ruby can be viewed as copying the philosophy or of cross-compiling to or generating JavaScript, or possibly emulating JavaScript in Ruby.
React is inherently a 'View' component, with additional libraries use a component and JSX approach to other capabilities. React-router is such a library.
React is not Angular. Angular is more of an MVC framework.
You probably want to go down these paths:
* Acquire the ability to code in JavaScript. Running on the browser implies code in JavaScript.
* Use Rails only as a server side REST or GraphQL endpoint. Alternately, use Rails to emit JavaScript and then use as REST or GraphQL endpoint.
* Non JavaScript code will not be able to use the latest JavaScript libraries.
It's good to think of the possibilities of what can be done, and this question suggests you are exploring.

Serverside rendering react components in Ruby on rails project without asset pipeline

I'm working on a Ruby on rails 4 project where we are using React/Redux for frontend. We are using Webpack and gulp for compiling javascript and css. We do not use rails Asset pipeline at all, it is disabled from config. All assets compile to public folder and directly included on views. Now all react components are rendering on client side. It is having his own disadvantages like visual flicks before js is fully loaded and problems on passing initial props from backend to frontend.
Is there any good way to compile react components on server side without using asset pipeline and passing props directly from rails views?
I am pretty sure http://reactrb.org does this, but it does use asset pipeline. The webpack components are brought in to the rails side, and then wrappers are automatically built so you can interface to the webpack components from your client side ruby components.
There was a lot of discussion on this at https://gitter.im/reactrb/chat and I don't know the details.
Also tutorial here: http://tutorials.pluralsight.com/ruby-ruby-on-rails/reactrb-showcase dealing with this issue as well.
So you could just use http://reactrb.org or figure it by reading their code.

What is the best way to integrate angular js app to Rails asset pipeline?

I had an application deployed on two servers : an apache for AngularJS and a Unicorn for Rails 4. Now I want to integrate the Angular app into the Rails one. What is the best way to do this?
In addition to Kevin B's comment, here's a cool tutorial on using Rails (Rails 4) to build a JSON REST API that interacts with an AngularJS frontend. Link: https://thinkster.io/angular-rails/ GL!

Resources