Any relation between emberjs route and rails route - ruby-on-rails

One project based on emberjs and rails.
When redirect to localhost/#lessons/2, the page works
when redirect to localhost/practices/2#/lessons/2,
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
so what's the difference between 'localhost/#lessons/2' and 'localhost/practices/2#/lessons/2'
If want to make 'localhost/practices/2#/lessons/2' works, how to set emberjs route?

so what's the difference between 'localhost/#lessons/2' and 'localhost/practices/2#/lessons/2'
Difference is the /practices/2 part. That's part of the url's path. By default ember will ignore that, it's just paying attention to the hash, which in bot cases is lessons/2.
Like firefox says, seems like the server is redirecting the request.
If want to make 'localhost/practices/2#/lessons/2' works, how to set emberjs route?
Hmmm... that url implies that server/rails is responsible for rendering practices/2 and that you have an ember app on the practices/2 page which should be rendering lessons/2? It's possible but that sounds like a very complicated setup. I'd be surprised if that's what you really want. Probably instead you will want to have localhost/#practices/2/lessons/2. With that setup just use normal ember routing as described here: http://emberjs.com/guides/routing/defining-your-routes/

Related

How to integrate EmberJS incrementally into an rails web app?

we're working on our opensource password manager cryptopus https://github.com/puzzle/cryptopus.
since our last release we integrated emberjs and are updating one component after another from classic rails webapp to emberjs. For now, we used locationType: "hash" to trigger emberjs parts.
one challenge we're facing now is to make sure the URLs are still the same after moving the UI components to emberjs. So we should get rid of "hash"-URLs for emberjs and still be able to call some legacy rails webapp URLs.
is there a way to ignore routes in emberjs and sending the request to the backend? any other ideas to make an incremental integration of emberjs possible? It would be OK if the SPA would be re-initialized after coming back from an class rails webapp URL.
some example routes:
/session/new -> send to rails backend
/teams -> handle by emberjs
/teams/42 -> handle by emberjs
/admin/users -> send to rails backend
it would be also possible to add a prefix for all emberjs handled routes like: /app/teams, /app/teams/42
we found a pretty simple solution for the problem.
in config/environment.js: removed rootURL, locationType: "auto"
configured all required routes in emberjs
created an frontend controller in rails which serves the ember files on first request
so now, some frontend parts of the app run with ember, others still with rails. the ember router doesn't care about URLs that are not configured. Pretty nice solution :)
have a look at https://github.com/puzzle/cryptopus to see the complete solution.

How to process requests for certain sub-domain(s) in Rails?

For example, I want my project link to look like http://blog.example.com. How can I make that kind of route in Rails 4? And how it can interact with controller?
The following stuff didn't work for me.
resource :article, constraints: {subdomain: 'blog'}
Your code is acting as a type of filter, so only requests already utilizing the subdomain 'blog' will invoke the route. You need to ensure that the web server itself is also setup to handle that subdomain and point it to your application.
Edit: Try checking out this post for further clarification (if you're on your local environment). https://reinteractive.net/posts/199-developing-and-testing-rails-applications-with-subdomains

Can I build part of my website in Ruby on Rails?

I have an existing website written in jsp. I want to rewrite a part of the website. The url for that section can either be newpart.mysite.com or mysite.com/newpart.
Will it be possible to rewrite this new part in Ruby on Rails? How does the routing works for both the url options.
Yes, you can use ROR for a portion of your site.
If your using a webhost they will route the domain to a folder on your server.
The way you worded your question, it seems as if your "newpart" will be a separate interface than the rest of the code for your site. You can act as if they are on different servers basically.
Yes you can do that.
For your options:
If you point the whole subdomain at rails: newpart.mysite.com, then all you have to do is tell apache (or whatever you use) to redirect that URL to your RoR app - and the app will happily continue from there without any changes to routing.
It would be more complex if you wanted to use: mysite.com/newpart ... so if you have a choice, I'd go with the subdomain.

When to use routes vs. rewrite rules?

I'm trying to debug a problem with routing and I've just realized that MVC routes do something extremely similar to url rewriting but I don't have a good understanding of which situations call for routing and which call for url rewriting. Can someone please explain where these two technologies differ and for which situations each is appropriate?
Url Rewriting analyzes the requested URL and changes it to a different URL on the same server. The URL rewriting module runs early in the request-processing pipeline, modifying the requested URL before the Web server decides which handler to use to process the request.
Routing is a request-dispatching mechanism that occurs after Url Rewriting. When a request is made to a Web server ASP.NET routing looks up the requested URL path in the list of registered routes. If the route is found, the corresponding handler for that route is invoked to process that request.
Use routes when you are developing a new application or maintaining an existing one. Use Url rewriting when you want to patch a legacy application without changing it internally.
http://www.iis.net/learn/extensions/url-rewrite-module/iis-url-rewriting-and-aspnet-routing

What is the best way to test SSL-only URLs with Capybara?

I've gone round and round trying to come up with the cleanest / easiest way to write request specs for certain pages of my site. I basically need a way to get Capybara to load pages that only accessible over https. Here are the pertinent details:
I'm currently using RSpec, Capybara and FactoryGirl on Rails 3.1.0
Its an e-commerce site. Some controllers force all actions ssl using the new force_ssl method in the controller class definition while some do not. I need the cart and checkout pages to be always https://, of course, while the rest of the site should remain accessible over http://.
I would be OK with somehow stubbing the SSL aspect of the requests if only I knew how to do it!
I'm sure many people out there have faced this same challenge. How did you do it?
What Capybara driver are you using? It should work fine with Selenium.

Resources