Custom homepage not showing up on Heroku deploy - ruby-on-rails

I'm just starting out with rails and have been deploying my mini app to heroku as practice. Everything seems to be working fine, except for the home page. No matter what I've done, I still see the "Welcome aboard, you're riding Ruby on Rails" page. I've deleted public/index.html, and included the following line in routes.rb:
root to: 'static_pages#home'
This works fine on my own machine, but refuses to work when I deploy to Heroku. Any idea what would be happening?
Edit: Here's the rest of my routes.rb, not sure if it will help:
SampleApp::Application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :comments
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
root to: 'static_pages#home'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
end

Remove the public/index.html file by doing
git rm public/index.html
git add (any other files you want to the commit) #optional
git commit -m "removing public index"
git push heroku master
Since, heroku does a git based deployment - removing from just local will not help.

Related

My routes file doesn't match expected result

Thanks in advance for any help.
I'm working my way through Michael Hartl's "learn enough" RoR lessons and am at the point where we're working with authenticating users via sessions.
Per the lesson, I've just run rails generate controller Sessions new and nothing blew chunks:
$ rails generate controller Sessions new
Running via Spring preloader in process 4407
create app/controllers/sessions_controller.rb
route get 'sessions/new'
invoke erb
create app/views/sessions
create app/views/sessions/new.html.erb
invoke test_unit
create test/controllers/sessions_controller_test.rb
invoke helper
create app/helpers/sessions_helper.rb
invoke test_unit
invoke assets
invoke coffee
create app/assets/javascripts/sessions.coffee
invoke scss
create app/assets/stylesheets/sessions.scss
However, there's a discrepancy between what the lesson says routes.rb should look like and what it actually does look like.
Expected result in routes.rb, as implied by the lesson:
Rails.application.routes.draw do
root 'static_pages#home'
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
get '/signup', to: 'users#new'
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
resources :users
end
Actual result in routes.rb:
Rails.application.routes.draw do
get 'sessions/new'
root 'static_pages#home'
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
get '/signup', to: 'users#new'
post '/signup', to: 'users#create'
resources :users
end
Am I missing something obvious? Why the difference?
I feel like there's a missing chapter between here and the last one, which only explains the really high level difference between browser-close-ending sessions and cookie-expired sessions.
You ran rails generate controller Sessions new, which means you want to generate a controller with the new action only. By default, new generates the view route (GET) and the actual resource creation route (POST).
To create the controller and routes following the CRUD pattern, you should run rails generate controller Sessions.
Solved.
The reason for the discrepancy is that rails generate controller Sessions new only generates the GET route #vnbrs mentioned.
The lesson calls for 3 routes that need to be supported: a GET request to the login form, a POST request to create the session, and a DELETE request to destroy the session.
Those need to be added to routes.rb manually:
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
Beginner's disorientation, I couldn't see the forest for the trees and broke my brain. (P.S. I don't recommend trying to tackle this tutorial discontinuously over a series of months...your brain does NOT pick up where it left off.)

Deploy static pages to domain root and rails application to subdomain

I'm following Michael Hartl's Rails Tutorial and deploying to Heroku.
I have static pages that are public to every web visitor and dynamic and "protected" pages that require the user to sign in in order to view them. Currently all pages are deployed to the website's root: example.com/static-page and example.com/users/1/
My objective:
deploy static pages to the root, like example.com/static-page
deploy rails' pages to a subdomain, like app.example.com/users/1
I assume the solution involves changing the routes file. Is there any tutorial or video explaining how to do so? I'm a newbie on Rails.
My routes file:
Dcid::Application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]
root 'static_pages#home'
match '/home', to: 'static_pages#home', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'
You could either have a controller serving your pages or simply put your HTML files in public an treat them as assets.
In either case if they are really static, you might want to cache heavily or put a CDN in front of everything.
You'll want something like this:
#config/routes.rb
root 'static_pages#home'
#Subdomain
constraints subdomain: 'app' do
resources :users
end
#Pages
pages = %w(home about)
for page in pages do
get "/#{page}", to: "static_pages##{page}"
end
#Resources
resources :users do
get :new, as: :collection
end
resources :sessions, only: [:new, :create, :destroy] do
get :signin, action: :new, as: :collection
delete :signout, to: :destroy, as: :collection
end
This will create the routes you need. However, you won't be able to use a subdomain on Heroku, unless you use a custom domain

Rubymine doesn't understand path helpers

I'm using Rubymine (5.4.3.2.1) for Hartl's RoR tutorial and I'm having some troubles with path helpers. root_path works just fine but rubymine says 'cannot find xxxx_path' for the rest actions in my controller.
Rspec and Rails server are working just fine with those same path helpers!!
My routes.rb:
SampleProject::Application.routes.draw do
get "users/new"
root 'static_pages#home'
match '/signup', to: 'users#new', via: 'get'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
end
I also tried to use get instead of match but that didn't help.
Ruby is a dynamic language and therefore some things are hard to parse intelligently for the IDE.
However showing routes and helpers like "people_path" etc should work, but you must restart the server if you change it!

Rails app w/ Heroku - Home page doesn't exist

My app runs perfectly on my localhost, but when I push it to Heroku, my home page gives me a message that says 'The page you were looking for doesn't exist.' Other pages (not all, but most) within the app display correctly on Heroku. Here is the output from running heroku run cat config/routes.rb:
Running `cat config/routes.rb` attached to terminal... up, run.8019
SampleApp::Application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :relationships, only: [:create, :destroy]
resources :teams
resources :players
resources :matchups
root 'static_pages#home'
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
match '/updatepts', to: 'static_pages#updatepts', via: 'get'
match '/findMatchup', to: 'static_pages#findMatchup', via: 'get'
The other page that notably does not display is matchups/:id. Any ideas as to why this is displaying with no problem locally, but will not work on Heroku? Thanks!
Edit: I am running Rails 4 w/ Ruby 2.
My underlying problem was that a partial that was being rendered on my home page (and the one other page not displaying) was calling a field that was nil because the data in my heroku database was not as extensive as the data in my local database.

Error with changing routes, following RoR tutorial

I am having a problem with section 5.3.2, where you are changing the routes from ..static_pages/help to ../help and so on for the help, contact and about pages.
Those three work fine. But when I enter the hyperlink for the home page it doesn't appear. There are no errors when I run bundle exec.
Even when I click on the links on footer and header they work correctly but the home always redirects to the default Rails tutorial page.
I deleted the public index.html via Git.
Code for config/routes.rb
SampleApp::Application.routes.draw do
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
.
.
.
end
Please check rake routes to confirm file public/index.html.erb has deleted.

Resources