views:

470

answers:

2

Hello!

I am developing an app in RoR which has static and dynamic parts. The static portion is placed in the public/ folder of the app. Now if i have an index.html in my public folder then i will not be able to use the routes configured in my routes.rb The default configurations like map.connect /:controller/:action will not be usable if i have an index.html. So i removed the index html.

Now i have a static page startpage.html in my public/ folder which has to be the starting page of the app. And the i have links in it for other static/dynamic pages.

The RoR app is hosted in apache and i tried to configure the Virtual Host configuration by adding the DirectoryIndex param so that when ever a request comes for the site it will direct it to the startpage.html but still it takes me to the default controller that i have specified in routes.rb with map.root

I dont want to add a dummy controller and action and create a view which has the startpage and configure routes.rb to use it as the root. What i am looking to do here is

Basically startpage.html should be my first page in the app served as a static page from the public/ folder. This will then have links to other pages and controllers/actions

Here i am not able to apache to redirect to the html page instead of passing on the control to rails application. Directory listing is also enabled by using Options Indexes but still no change.

Any pointers anyone?

A: 

You can made a URL rewrite from index.html to your startpage.html

RewriteRule /index.html /startpage.html
shingara
Hey...basically my req is to map / to /startpage.htmlI tried to map / to /startpage.html using RewriteRule but still the request was reaching the rails engine.
meetraghu28
to be clear - req is to map "xyz.com/" to "xyz.com/startpage.html"
meetraghu28
+5  A: 

Now if i have an index.html in my public folder then i will not be able to use the routes configured in my routes.rb.

This is incorrect. The solution of your problem is to rename startpage.html to index.html, which will cause requests for / to be served by index.html, and any requests for /:controller/:action will be passed along to Rails Routing engine.

Apache will first serve anything it can find in the public directory. If it's not available, then it passes the request off to Rails (this is how page caching works).

With index.html in place, you do not need map.root, as it will never get requested (remember, Apache serves / with index.html). And you don't need any special directives either.

Jonathan Julian
Jonathan,Thanks for pointing out the mistake.I removed the map.root config from my routes file,added startpage.html as index.html. Things work fine.Is there anyway to have both the mapping mutually exclusive. I mean only for the first time when i hit "/" i should get index.html and for subsequent request for "/" should be taken care by the map.root configuration.Consider a sample scenario like a login page. So the first page(index.html) is the login page. So once logged in i should not be moved back to the login page when the i accidentally/intentionally requests for "/"
meetraghu28
What you are describing could be done in a `root_controller` that acts as a switchboard. Rename index.html to startpage.html. Add `map.root :controller => :root`. Then in `root_controller`: `render :file => 'startpage.html'` if not logged in, and `redirect_to account_path` or something when the user *is* logged in.
Jonathan Julian
Okay that is definitely doable. But i am wondering why do we have to get into any controller or rails engine to do this. For a startpage or login page when the content is totally static it doesnot make sense to get to the rails engine which might marginally slow down the load time of the page.
meetraghu28
You want a different thing to happen "once logged in". You need to run code to do that.
Jonathan Julian