News for hackers. Stuff that matters.
Re:How to Wire Up Ruby on Rails and AngularJS as a Single-Pa... by davedx on Tuesday July 22, 2014 @10:12AM (#8069058)
Nice writeup. I tried to do the same thing a few months back and gave up. How did you handle getting your browser to talk to a server running on a different port? (Cross-origin requests).

I have to say though, Rails used to be known for "convention over configuration", but when I've tried to use it lately I've found it becomes almost as complicated as configuring enterprise Java projects.

Re:How to Wire Up Ruby on Rails and AngularJS as a Single-Pa... by patrickread on Tuesday July 22, 2014 @10:26AM (#8069129)
> How did you handle getting your browser to talk to a server running on a different port? (Cross-origin requests).

https://github.com/cyu/rack-cors

I used that gem recently, and it fixed my issue. Just added the dev, prod hostnames explicitly in the origins list in my application.rb.

Re:How to Wire Up Ruby on Rails and AngularJS as a Single-Pa... by jasonswett on Tuesday July 22, 2014 @10:15AM (#8069076)
I didn't have to do anything special to allow CORS, and now that I think of it I'm not sure why, because it's been necessary on other SPA projects I've been involved with. Maybe because both servers are localhost. That would be a good thing for me to figure out and include in the post. I'm kind of learning all this in public.
Re:How to Wire Up Ruby on Rails and AngularJS as a Single-Pa... by tragic on Tuesday July 22, 2014 @10:19AM (#8069095)
> How did you handle getting your browser to talk to a server running on a different port? (Cross-origin requests)

Having run such things on entirely different servers, never mind localhost ports, what I needed to do was set the Access-Control-Allow-Origin http header in the rails controller (same principle applies to other frameworks). One simple guide is here: http://madhukaudantha.blogspot.co.uk/2011/05/access-control-...

Slightly ruined by that dreadful blogger interface, but there you go.

Re:How to Wire Up Ruby on Rails and AngularJS as a Single-Pa... by miles_matthias on Tuesday July 22, 2014 @10:30AM (#8069147)
I wrote about using Rails + AngularJS in a CORS way -- http://dojo4.com/blog/angularjs-service-rails-api

Hopefully it helps you!

Re:How to Wire Up Ruby on Rails and AngularJS as a Single-Pa... by aantix on Tuesday July 22, 2014 @11:37AM (#8069522)
>I have to say though, Rails used to be known for "convention over configuration", but when I've tried to use it lately

>I've found it becomes almost as complicated as configuring enterprise Java projects.

Do you have any specific examples of where you were having troubles?

Re:How to Wire Up Ruby on Rails and AngularJS as a Single-Pa... by mbell on Tuesday July 22, 2014 @10:26AM (#8069127)
> How did you handle getting your browser to talk to a server running on a different port? (Cross-origin requests).

He's using grunt-connect-proxy to proxy the API requests through the grunt server so there are no CORS requests in this setup.

Re:How to Wire Up Ruby on Rails and AngularJS as a Single-Pa... by cmpb on Tuesday July 22, 2014 @10:27AM (#8069134)
You could just run the api on /api via an nginx proxy, that way it uses the same domain. I.e. catch all the traffic coming in to /api and route it to the proxy for you rails app.