Bibek Sharma Bibek Sharma - 3 months ago 25
Ruby Question

Add additional font-end folder to serve static html pages in Rails

I'm trying to display some static landing pages on my Rails application. As of now I'm putting all the static

.html
pages inside the
my_app/public/website
folder and mapping routes like

match '', :to => redirect('/website/index.html')


There is a link on that static page and on clicking on that link user will be redirected to my main rails application.

Now I need to move folder inside of
public
ie,
website/*
to root directory like
my_app/website/
.

I've changed folder structure as above and change routes as

match '', :to => redirect('website/index.html')


and I'm getting this error

ERROR URI::InvalidURIError: the scheme http does not accept registry part


This was just the hit and trial approach and to be honest with you I'm not sure if it is possible to do so. I am guessing if there is any configuration options that is present that would allow me to make any root level directory to server static assets.

Many thanks

Any suggestions will be appreciated.

Answer

You need to define the folder that is to be used as public in config/application.rb file as follows.

paths['public'] = 'website'

And then you can define your routes as

get '', :to => redirect('index.html')

Alternatively, you can put the whole thing inside the frontend folder, this way there will be less chance of any name conflict if you have multiple static pages

# config/application.rb
paths['public'] = 'frontend'

and

# config/routes.rb
get '', :to => redirect('website/index.html')

Hope it helps.

Reference

Comments