Can I build part of my website in Ruby on Rails? - 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.

Related

How do I set up a Rails page as a subdomain of another site?

We're trying to create pages in our Rails app that will eventually live on a subdomain of another partnering site. This would be like StatusPage, which allows users to create a status page with their account on the StatusPage site and then attach it to their own subdomain (e.g. status.usersite.com).
For example, if we wanted one of our pages (www.oursite.com/users/bobsplumbing) to be a subdomain on another site (ourservice.bobsplumbing.com), how would we go about it?
If it's useful info, we use Heroku to host the Rails app and we also utilize Route 53 and Cloudflare.
From your example I understand that you want to have multiple web apps since that would be your customer domain and your page will redirect to that page.
You will be better off to do NGINX (or whatever you use) redirects since they are faster and will take less time, being cached by the browser after the initial load.
To answer your question you can add this code to your routes:
sites = %w(bobsplumbing catsandboots)
sites.each do |name|
match "users/#{name}" => redirect("https://ourservice.#{name}.com")
end
You can also have a look at apartment gem.

Ember 2 Routing Subdomains

I have a Ember 2 application (ember-cli) that uses a Rails API as the back end. For this application, I have enabled Wildcard DNS with my DNS Provider (Cloudflare). When a user signs up with my website, I want them to be able to use their subdomain to access their public home page.
For example:
A user named Steve signs up for my site located at awesome.com. So Steve browses to steve.awesome.com, which internally would translate to awesome.com/users/steve. How do I setup my Ember routes such that it can route based off of the subdomain?
I have come to a solution, but it isn't exactly what I was initially looking for. I realized there really isn't a reason why the URL has to be awesome.com/users/steve, and instead have decided that their subdomain (or custom domain) will act as their identifier. So let's say Steve browses to steve.awesome.com, I will figure out the host via window.location.hostname, and use that as a lookup key to pass to my Rails API and retrieve user data.
Not exactly the solution I originally was seeking, but it solves my issue!

Any relation between emberjs route and rails route

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/

Subdomain URL Rediretion In MVC

I am new in MVC, I have a list of url redirection:
•website1.domain.com goes to domain.com\websites\1
•website2.domain.com goes to domain.com\websites\2
This is a dynamic mapping like this: websiteN.domain.com goes to domain.com\websites\N
How can I do this in MVC, Do I need to use routing? or I need only URL redirection?
This is a duplicate question.
Everything you need can be done in IIS.
please visit this Stack link:
handling sub-domains in IIS for a web application
(same user asked this question and reposted How can we make an ASP.NET MVC4 route based on a subdomain?)
you can get more detailed information:
http://www.dotnetexpertguide.com/2012/04/aspnet-iis-dns-records-sub-domain-on.html
http://content.websitegear.com/article/subdomain_setup.htm
I've had a similar situation where I needed to make sure that the language code was in the url.
My solution was to write an http module. You'll want this module to inspect the request and see what subdomain the request is under. If it is a subdomain, then you'll want to redirect them to the correct directory under domain.com

Map a domain to an MVC area

Anybody got any experience in mapping a domain to an MVC area?
Here's our situation:
Old system (still active but will soon redirect to new store):
www.example.com - our main site where we send traffic
store.example.com - our store site which is a completely separate site that is indexed in google
New system:
www.example.com - same site as before
www.example.com/store - new store site - built in an ASP.NET MVC area
Because store is a separate domain google gives it a separate entry in the search results. I'd like to keep this benefit in future but wondering whether or not there is a good way to map a domain (store.example.com) to the MVC area or if its just going to be more trouble than its worth.
PS. I'm not trying to keep existing indexing - its a completely separate store so thats not possible. I just want to redirect to the corresponding page in the new store. I'm just trying not to lose the benefit of two domains for SEO purposes.
I would use URL Rewriting, either in ASP.NET or in IIS7 Application and Request Routing (ARR) to change incoming requests for store.example.com/... to example.com/store/....
MVC will have no issue with this - it doesn't get to see anything but the new URL and it will generate links only for the new layout.
Other alternatives:
Create a website for the store.example.com that just does a wildcard 301 redirect for each page to the corresponding page on the new site.
If the URLs don't overlap at all, point the old domain to the new MVC site and add duplicate routes for each action, e.g. shop.example.com/info.aspx?item27 might have a route "/info.aspx/{pathinfo*}" ... which loads an Action that knows how to handle the old URL parameters and can do a Redirect to the new Action.
I have sites where there are many URLs mapped onto the same Action - in fact, every legacy URL that has ever been used for a page still works today, including even the old .ASPX URLs which are now served up by an MVC Action. Some legacy URLs are dealt with using a 301 response, others which legitimately have duplicate content on the site are handled as normal but the page also includes a canonical URL to point out which one is the preferred URL.

Resources