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

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.

Related

I get error "uninitialized constant ContactController"

routes.rb file is
Rails.application.routes.draw do
root 'pages#home'
match '/contact', to: 'pages#contact', via: 'get'
match '/home', to: 'contact#pages', via: 'get'
pages_controller is
class PagesController < ApplicationController
def home
end
def contact
end
end
I get routing error saying "uninitialized constant ContactController". Does anyone know how to fix this?
Do Change your routes.rb file
Rails.application.routes.draw do
root 'pages#home'
match '/contact', to: 'pages#contact', via: :get
match '/home', to: 'pages#home', via: :get
end
Would work!!!
In Rails 4 with match methods must specify HTTP method otherwise would get RuntimeError "You should not use the match method in your router without specifying an HTTP method. (RuntimeError)"
match is deprecated. Try
root 'pages#home'
get '/contact', to: 'pages#contact'
get '/home', to: 'pages#home'

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 Cookie Detection Script Fails

I wanted to make sure that users have cookies enabled for my site, so I used this guide.
However, when I run my server, I gut this error:
syntax error, unexpected $end, expecting keyword_end
map.cookies_test “cookie_test”, :controller...
Here's my application_controller.rb :
class ApplicationController < ActionController::Base
protect_from_forgery
include CookieDetection
include SessionsHelper
end
and my routes.rb :
Basketball::Application.routes.draw do
map.cookies_test “cookie_test”, :controller => “application”, :action => “cookie_test”
resources :games
resources :teams
get "teams/new"
get "games/new"
resources :users
resources :sessions, only: [:new, :create, :destroy]
root to: 'static_pages#home'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
end
Update
I have changed my quotes from "smart" quotes to plain quotes (as per Edward), but I am now getting the error:
undefined local variable or method `map' for#
<ActionDispatch::Routing::Mapper:0x007ff9ca996800> (NameError)
Update
I have changed Map to Match (as per Edward) and am now getting the error:
`match': wrong number of arguments (0 for 1) (ArgumentError)
In your routes file, it look like you've got "smart" quotes “” ,rather than plain "
I expect you've cut and pasted them by mistake.
Edit
Change map to match - map is rails 2

Custom homepage not showing up on Heroku deploy

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.

Resources