SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple sites in 1 rails project?

    Hi

    I have a number of small sites each targeting a diferent niche but with very similar structure and most are only a few pages each.

    I was thinking of setting up a rails app that would contain all of these small sites in the one app so that I dont have to update and manage each one individually.

    Is there a way of changing the style sheet and possibly layout in rails depending on the url so that I could just use one app to serve all the sites?

    Can anyone think of any implications of doing this such as seo problems?

  2. #2
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Location
    Wherever danger lies...
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Theming is easy. Define multiple layouts in app/views/layouts/ and have code like this in your ApplicationController (assuming I remember the exact syntax):

    Code Ruby:
    layout :site_layout
     
    def site_layout
      # check URI for which site this is
      # return the name of the appropriate layout file
    end

    I think the URI is accessed with request_uri.

    I don't know anything about SEO.
    There are some things you shouldn't try to code at home.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AllTom View Post
    Theming is easy. Define multiple layouts in app/views/layouts/ and have code like this in your ApplicationController (assuming I remember the exact syntax):

    Code Ruby:
    layout :site_layout
     
    def site_layout
      # check URI for which site this is
      # return the name of the appropriate layout file
    end

    I think the URI is accessed with request_uri.

    I don't know anything about SEO.
    Its actually easier than that..

    If each mini-app is its own controller..
    Code:
      #if you have
      class AppOneController < ApplicationController
      end
      
      class AppOneSecondController < ApplicationController
        layout :app_one
      end
    
      class AppTwoController < ApplicationController
      end
    And then if you have in app/views/layouts:
    app_one.html.erb
    app_two.html.erb

    It shouldl automagically apply the correct layout
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  4. #4
    l 0 l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    AllTom's idea of using layouts is likely just fine, though if these sites start growing it could become a bit of a pain later on.

    Quote Originally Posted by wardo View Post
    Can anyone think of any implications of doing this such as seo problems?
    As far as SEO considerations... I don't think there's anything really awry here. One thing that might pop up is the definition of a "site"... are you just slotting them in different directories? (/site-a/content) In that case... there could be some problems with search engines figuring out your home page (they might only give you the "homepage" bonus to the root URL of your domain). To be honest, though, if these are just minor sites you shouldn't really run into any problems.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent, thanks for your help guys. I dont think the sites are likely to grow much but I see what you mean about search engines having difficulty seeing what the root domain is. I have not worked out how I am going to organize the content yet but I will probably put the content for each site in seperate directories.

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks pjleonhardt

    How would I load each controller based on the url? eg:

    www.app1.com would have to go to AppOneController and so on.

    Would that be set in environment.rb using request_uri?

  7. #7
    l 0 l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wardo View Post
    Thanks pjleonhardt

    How would I load each controller based on the url? eg:

    www.app1.com would have to go to AppOneController and so on.

    Would that be set in environment.rb using request_uri?
    You can set it up with routes, so if you see a request coming in for "/super-app-1" it directs it to the proper controller.

    The more I think of it, though, the more it feels kinda odd making Rails work with smaller sites. Perhaps you want to ditch Rails altogether and look at Merb or Sinatra instead?

  8. #8
    SitePoint Enthusiast TomK32's Avatar
    Join Date
    Mar 2008
    Location
    Berchtesgaden, Germany
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to look into mephisto which is a blog software and works just like this. I'm running about ten blogs with only one app, all different themes.
    just a geek trying to change the world
    I'm a ruby on rails developer in Vienna, Austria. My github.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •