Angular to use Rails templates + Routing [closed] - ruby-on-rails

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Rails provide a strong template engine out of box and i like it. I was wondering if there is any way to use it? So maybe angular templates can be wrapped inside rails that lives in our views directory. We can call it metatemplates.
So instead of my angular templates living in asset directory which i feel is not a good way?
Also i need to make use of rails routes inside my angular at some point. For example Signout functionality.

AFAIK, you could let Ruby serve up angular templates. Ultimately Angular is requesting a resource from the server via a url, and expects it to be an html fragment. If Angular is requesting from Rails, then you could use Rails functionality to serve up the html fragment (ie template). So you could write your angular templates as a Rails partial using erb or haml, which Rails would then serve up as html to the requester.
As a side note, it gets complicated to separate concerns doing this approach. Keep it clear in your mind what Rails needs to do as an application server, and what Rails needs to do as an application service. The application server needs to serve up the Angular application (i.e. js and html that will be managed by Angular on the client side). The application service needs to serve json that will be consumed by Angular.

Related

What's the intended way working with angular and ruby on rails [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I've just startet my first project with angular in combination with ruby on rails. There isn't that much documentation outside. After some research I'm confused about this combination.
In a normal angular project you would server the content and the style via angular. But in rails this doesn't seems to work out of the box, so there must be an other intention.
Is it really meant to serve the templates and styles using rails views and than add only the client logic using angular?
Angular is not really meant to work with any kind of backend templating. Angular is meant for Single Page Applications (SPA) that work on their own. Usually, you would have one or more APIs to communicate with your Backend (usually via REST, sometimes GraphQL). Templatiting, Styling and Bindings should be done by Angular alone.
So in your case you would only supply a REST Based API using Rails and do all of the frontend work in your Angular application, which in turn communicates only via REST with your Rails Backend.

Are there any RoR projects exploring the use of web components? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
This might not be an acceptable question for Stack Overflow but I didn't know where else to ask the question.
Web Components has been "about to happen" for a very long time. It now appears that most browsers have most of the required pieces natively instead of using polyfills (which always worried me).
I'm wondering if Ruby On Rails is planing on moving to it or if there are any projects creating web components as well as Rails server code to take advantage of them.
I'm wondering if Ruby On Rails is planing on moving to it or if there are any projects creating web components as well as Rails server code to take advantage of them.
The webpacker gem makes it easy to include some of the JS frameworks for non-native web components like Vue or React, but you can also use it with Polymer to support native web components. We do this at my work, and we don't necessarily use webpacker for it right now but I can assure you it's a very good gem.
Here's more info: https://github.com/rails/webpacker
Here's how you'd initiate a new rails project with webpacker set up for VueJS for instance:
rails new myapp --webpack=vue
I'm not sure if rails is going to implement web-components as a built-in feature or not but the motive behind adding webpacker as default in rails 6 is to improve the integration of front-end/javascript libraries. So, you can use vue-js, react-native easily along with your rails app and build components in it.
I'm personally using many vue-js components in rails projects and having no issue with that.
P.S: Same as the question this might not be an acceptable answer :P

How is/can back- and frontend be separated in Ruby on Rails? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am evaluating frameworks and I would like to understand Ruby on Rails architecture better.
Coming form a Java background I developed components separately namely front and backend. More concretely for my backend I use Dropwizard and start a HTTP server. For the front end I use a nginx webserver with some forwarding to connected to my backend api via REST with Json objects. The front end is just plain html and a little JavaScript in vue.js.
Now I am very new to the ruby philosophy and I am quite unsure how Ruby accomplishes the task of separating front and backend. I read some some notes refering to rails-api that can create a HTTP server. But I am still unsure if and how ruby and rails builds this stack.
I would be glad if someone could explain Ruby on Rails architecture a little bit and maybe point to some tutorials how to accomplish a project with the stack above. Moreover is the stack I used to build in -as mentioned with Java above - even the Ruby way?
Right now rails-api has been deprecated and merged back into the Rails core. You can use standard Rails to build API routes similar to Dropwizard and then have a frontend framework, like Vue, pull the data using Ajax. You will still use a reverse proxy in front of the Ruby app like nginx so that is no different than Java.

Rails + AngularJs web app [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm going to create some AngularJS/Rails app, but I'm a newby in developing with AngularJS. So, I have one question: should I divide my project with 2 parts: the first one is just HTML/CSS/JS code and the second one is Rails API? I also can do all work in the Rails project. What should I prefer? Thanks in advance!
Personally I feel that the clean way is to put the html files under the public folder. Also this will make it easier to point Angular routes to your html files as you don't have to mix .erb with your javascript, which also gives you the ability to use pure coffeescript everywhere (You cannot make .coffee.erb files sadly).
The folder structure for all my Angular applications was following:
Angular coffee files:
app/assets/javascripts/angular/
In there I have seperate folders for controllers services and directives. In controllers folder I have the same namespacing going on as in Rails controllers folder.
So if there is a content namespace where I have likes and media controllers inside of it, then it looks the same in Angular folder.
Angular template files:
public/templates/
In public/templates where I keep the .html files, I follow the rails way of naming folders and files, and also keep the namespacing. So if users folder has an index page and a show page then I also have show.html and index.html.
Here are some very good examples where people have made Angular - Rails applications:
CafeTownsend
Rails4-AngularJs example

Is it possible to set up a redirection rules outside Rails application? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a Rails application and it is working great. For some specific page I would like to redirect it to some other page when a user requests that page, but what I want is to do a redirection outside Rails code, so the settings ,at the end, would have to be outside rails code itself.
There could be a htaccess file to modify as an outside file to redirect to some other page, but I haven't done that so far with rails.
So, the questions is - Is that possible?
You need to handle the request before it hits Rails app. For example you can create a rewrite rule in a configuration of HTTP server you're using (nginx, apache, etc).
See these links:
How to redirect in apache?
How to redirect a url in NGINX
If you don't have access to your server configuration (e.g. you're on Heroku) you can use refraction gem (https://github.com/joshsusser/refraction). It is a middleware, so in fact you're putting this redirection logic inside Rails, but at least it does not hit your controllers.
Rails allows for external URL's in redirect_to, so you can do something like:
redirect_to "http://www.example.com/interesting_page"
If that is what you were looking for.

Resources