Ruby on Rails only showing what is in public folder - ruby-on-rails

I am new to rails and have developed a simple rails application on my machine that works when hosted locally with WEBrick.
I understand that you need to delete index.html from the public folder and set the proper root in config/routes.rb to point to the controller you wish to be root, which I did with:
root :to => 'home#index'
(On the remote host)
When I have the index.html file in the public folder and go to mywebsite.com/myapp I see the page.
When I delete the index.html page from the public folder I get a 404 and my app does not run.
Any idea as to why my app is not running when I deploy it to the remote host?

If you set your root to home#index, then you need to have a view app/views/home/index.html.erb. The corresponding controller method would be def index, located in app/controllers/home_controller.rb.

Related

Ember CLI app inside a Rails engine

I'm making a Rails engine that has an /admin route. I'd like to create this admin interface with Ember CLI.
I know rails will automatically precompile any static JS/CSS that live in my engine's lib dir, and only load them when the parent application mounts my engine and visits that route. However, I'd like to use Ember CLI to build the admin interface.
What would be a good way to do this? Ideally I'd like to keep Ember CLI builds out of the repo.
My solution involved storing a build of the Ember CLI app in the engine.
I wrote a rake task that runs ember build and moves the static dist into the public/my-engine directory, and merges those public static assets with the host app's public folder.
Here's the task for our particular project:
namespace :admin do
task :build do
Dir.chdir('admin') do
sh 'ember build --environment=production'
end
# Copy the dist to public
FileUtils.rm_r 'public/front_end_builds'
FileUtils.mv 'admin/dist', 'public/front_end_builds'
# Move the index out of public
FileUtils.mv 'public/front_end_builds/index.html', 'app/views/front_end_builds/admin/index.html.erb'
end
end

Rails page not showing in Heroku

I deployed a simple Rails project on Heroku and I'm having some trouble. I set my root page as:
root 'landing#index'
This page works fine when I cd into the project, and start rails server and go to localhost:3000. I pushed to Heroku without error using git push heroku master. However now, if I do heroku open, I get the following message on the page:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
The logs don't show anything significant as well...
Make sure that you have the following:
A LandingController
A view page at the path app/views/landing/index.html.erb
root 'landing#index' on the second line (after Application.routes.draw)
The live repository is up to date
https://devcenter.heroku.com/articles/getting-started-with-rails4#write-your-app
Failing that, run heroku run rake routes. You should see a route like GET /landing/index landing#index and root / landing#index
If they don't appear, add the line resources :landing to generate the default routes for the landing controller.

ruby on rails web development using heroku

my app is not been uploaded on
heroku
only the first page with welcome to ruby on rails is displayed
my url is
my url link
Your deployed app is presently being overridden by Rails' default static index page. From config/routes.rb:
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
Therefore, first ensure that your root route is set:
# config/routes.rb
root :to => `root_controller#root_action`
Then, delete public/index.html, commit the changes to version control, and redeploy to Heroku.
First make sure you have correct routes. Then you commit the changes to the master branch and then:
git push heroku master
Hope this helps.

how to deploy rails action as site root

in routes.rb, I set a controller and a action as root, it works very well when I visit root in development mode.
now , I try to use nginx to hook rails app together, seemed nginx.conf need rails public folder which is not the root path set in the routes.rb.
index under public folder only can be a static html, how could I hook nginx with rails action as root?
Thanks for your answer!
nginx is only a webserver - have you installed something like Passenger as your app server to run your application in? It's perfectly normal to map the webserver to your public folder but then the application server will process the request and serve back your app for you

Resource mapping works locally but not on webserver

Edit:
Well maybe this can give a clue. When created a Rails app in cPanel on my web host, in order to access the app you need to create a rewrite rule. Which I did, but didn't know what it did. I tracked it down to it creating the following 2 files:
home/mydomain/public_html/.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:12030%{REQUEST_URI}" [P,QSA,L]
and
home/mydomain/.cpanel/ruby-on-rails-rewrites.db:
appname: helloworld
domain: mydomain.com
port: 12030
rewritebasepath: /home/mydomain/public_html
url:
It seems that the root URL gets sent to Rails, but any other URL does not and I get an Apache 404 (not a Rails 404). Is there something wrong in the .htaccess file?
Is the rewrite condition only for the domain root? If it is, how can I make it for any URL ?
Original post:
I'm trying to deploy a rails website that works fine locally but not on the web server.
The rails app starts fine and I can access the home page. But any other link results in a 404.
My home page is set from within routes.rb like so:
map.root :controller => "home"
I am using RESTful routes and it works fine locally. In routes.rb all I have is a bunch of
map.resources :posts
map.resources :images
...
If I change the map.root to another controller (i.e map.root :controller => "posts", then that single page will display fine as well, and all other links will return 404s, including the one that previously worked when it was the one referenced in map.root.
This is my first rails deployment so it might be me doing something wrong. My web host tech support told me it's a coding issue and that they can't help me.
My website directory structure online is like so:
/home/mydomain/etc/rails_apps/mysitedir/ <- rails folders (app, config, db, ...)
/home/mydomain/public_html/ <- nothing here
Also, the files that are in my rails public folder, do they need to stay in that folder or should they be put in the public_html folder on the web? Because right now they're not found either. If I put them in the public_html folder though, they are found from the home page (javascript and css and images).
In my error log in cPanel, it shows errors like:
[Mon Oct 05 08:19:41 2009] [error] [client XX.XX.XX.XX]
File does not exist: /home/mydomain/public_html/market,
referer: http://www.mydomain.com/
Where market is one of the links I'm trying to access from my home page, for example, and it's one of my controllers.
In short, the only location I can access is the root.
What am I doing wrong that I am getting all these 404s?
I do not have shell access, all I have is cPanel. This is with Ruby 1.8.5 and Rails 2.3.4, the (shared) web server is Linux + Apache 2.2.11 (Unix).
You need to get your web root to point to /home/mydomain/etc/rails_apps/mysitedir/public/ Maybe this can be configured in cpanel?
If you can get access the shell you would do something like(syntax may vary slightly):
ln -s /home/mydomain/etc/rails_apps/mysitedir/public/ /home/mydomain/public_html
Note that you need to remove public_html first, you should verify that there are no negative consequences of this.
The problem is with my web host. Still hasn't been resolved by them.
I came across the exact same problem and found a fix. In the .htaccess file, remove that first '$' so you have:
RewriteRule ^/? "http\:\/\/127\.0\.0\.1\:12030%{REQUEST_URI}" [P,QSA,L]
That first bit is a Regex, so the $ matches the end of the URL.
As a side-rant, this is the umpteenth problem I've had to solve today because cPanel sucks.

Resources