Rails Routing Broken In Production - Caching of routes.rb suspected - ruby-on-rails

Update: Turns out that this problem was because half my mongrel did not restart. Thanks all for help!
Hi folks, i have an urgent problem. Essentially, my routing works on my localhost. But when i deployed this to production, the routes does not seem to work correctly.
For example, given a new route "/invites" - sometimes i will get a 404, and sometimes it will work correctly.
I suspect there is some caching going on somewhere, but i am not sure.
Logs: when a page is not found (when the routes are supposed to be accurate)
Processing UsersController#network
(for 67.180.78.126 at 2010-06-01
09:59:31) [GET] Parameters:
{"id"=>"new"}
ActionController::RoutingError (No
route matches
"/comm/role_playing_games" with {}):
app/controllers/application_controller.rb:383:in
prev_page_label'
app/controllers/application_controller.rb:238:in
log_timed_info'
app/controllers/users_controller.rb:155:in
network'
app/controllers/users_controller.rb:151:in
network'
app/controllers/application_controller.rb:44:in
turn_on_query_caching'
app/controllers/application_controller.rb:43:in
turn_on_query_caching'
app/controllers/application_controller.rb:42:in
turn_on_query_caching'
app/controllers/application_controller.rb:41:in
turn_on_query_caching'
app/controllers/application_controller.rb:40:in
turn_on_query_caching'
app/controllers/application_controller.rb:39:in
turn_on_query_caching' haml (3.0.6)
lib/sass/plugin/rack.rb:41:in `call'
Rendering
/mnt/app/releases/20100524233313/public/404.html
(404 Not Found)

From the little you have posted, this definitely isn't a caching or routing problem.
It sounds like you are trying to generate a link to the previous page the person was on inside ApplicationController and you have a bug with it. You will have to post the relevant code from application_controller.rb.

Did you make sure you restarted your server (like apache, ngix or passenger)?
Also, sometimes a browser can cache urls, just close your browser and reopen it, see if that fixes it.
Also, once in a blue moon, I'll forget to push the code to GIT and therefore production server doesn't get the latest code. Just check that your server actually has the code there.

Related

Heroku app page not found

I deployed a rails app on Heroku. Everything was working fine. I pushed the code to Heroku master, and everything worked as expected. I also ran Heroku run rails db:migrate. No errors were thrown. I can even run the Heroku run rails console, and create objects, no problem. However, It does tell me that I have to type in User.connection, (Users are the only models I have in the app right now). When I type Heroku config I get expected output. Everything seems perfect. But, when I open the app, it says that the page is not found:
No webpage was found for the web address: https://my-api.herokuapp.com/
It's probably worth mentioning that It's a rails API, therefore, there are no views, and no root page. But despite that, I still don't get any responses when I make API calls with Postman. I simply get a 404 response. I would at least imagine that HTTP requests would work, but they don't. Any idea why?
Upon loading the app the logs say
ActionController::RoutingError (No route matches [GET] "/"):
does mean there is no root route? I thought for an API, there didn't need to be one?
ActionController::RoutingError (No route matches [GET] "/"):
It means that it is pointing to your app and search for root route but if that isn't defined in the routes file then it will show this error.
For API mode only means that it will not generate css and coffee files related to controllers.
Open App links to app and finds the root path and if it doesn't find then it this error occur.
Since you are using API mode thus this error will not be troublesome.
Check your routes.
Heroku can return such an answer when you just have no a root route.
If you have any specific routes you can try to go it and application will work.
https://my-api.herokuapp.com/return_mystuff

Routing error on ch 2 micropost rails tutorial (routing_error.html.erb within rescues/layout)

I'm working on the micropost toy_app in Chapter 2 of the Ruby on Rails Tutorial, and my site on the cloud9 url (http://rails-tutorial-[username].c9users.io/microposts/new) isn't working. I've tried a bunch of things to try to fix this (eg, ctrl c, starting rails server over, ctrl c again, pushing possible changes I missed to heroku etc), but the displayed web page toggles between the red and white "we're sorry but something went wrong" generic error and the blue/pink floral "No application seems to be running here! Cloud9 can't get you to your requested workspace" errors.
In the C9 dev logs show these two error over and over:
Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/routing_error.html.erb within rescues/layout
and
ActionController::RoutingError (uninitialized constant MicropostsController)
I've searched all over and it looks like most people with routing errors have different errors messages, and it's because they haven't defined their routes properly. I'm totally new to this, and I can't figure out what I'm doing wrong.
Previously (when I went through chapter 1 of the tutorial), my /users and /users/new pages worked, however now none of those URLs work either. Would this be related to a C9<>bitbucket<>heroku issue, or is it likely to be with my actual code? heroku logs didn't show anything meaningful.
My routes.rb file looks like this:
Rails.application.routes.draw do
resources :microposts
resources :users
root 'microposts#index'
end
For what it's worth, I started the tutorial on 12/25/15, which is the day that rails 2.3 was released-- however my logs show I'm on 2.2.1. I wonder if during the 20-30 hours since I started on 12/25, my rails version on c9 got outdated? I don't understand how that works since I'm using a cloud IDE.
I'm brand new to rails and haven't done any programming aside from a few classes in college-- any tips or pointers would be appreciated.
After starting over, I finally figured it out after another hour or so-- I had 2 problems. The first was that I'd only run one of the 2 necessary scaffolding commands in the tutorial (doh!). I discovered this by more carefully reading the c9 development log, and noticed a line that said ActionController::RoutingError (No route matches [GET] "/micropost"):. at this point I realized I was missing the micropost application controller, because I'd never created it with the 2nd scaffolding command: rails generate scaffold Micropost content:text user_id:integer
The other problem is that I didn't (and still don't) really understand how the rails server works-- so I was making my changes and not realizing that the server needed to be actively running for the website to load. When I run the rails server -b $IP -p $PORT command, it looks like it never finishes (eg, the $ for me to start my next command prompt never appears until I hit ctrl c). So I kept hitting ctrl c, not realizing I was killing the server that was hosting the web page.
What I did now was make all my changes, then run the server, then hit ctrl c when I need to make more changes.
Am I doing something wrong with the server stuff? Overall it's working, but it seems like there could be a better way.

Solution found: cPanel-created Ruby On Rails setup returns blank pages for any views

Solution found!
This appears to be a bug specific to Mongrel + Rails 2.3.8, the webserver used by Rails+cPanel. This is why it only shows up when you run the app from cPanel, but not when serving it locally via script/server.
For more details, see:
https://rails.lighthouseapp.com/projects/8994/tickets/4690-mongrel-doesnt-work-with-rails-238
The eventual workaround found is to put the following file in the /config/initializers directory of each new Rails 2.3.8 app:
https://gist.github.com/471663
Once I add this initializer, my Rails app functions as expected.
Original question:
I've gone through the very helpful tutorial at railsforzombies.org and am now ready to get a test RoR install going. My site is on a shared host, using cPanel. I've created the test application using cPanel, and it's set up at ~/rails_apps/blog. I created a rewrite that redirects mydomain.com/testblog/ to mydomain.com:12002, which is the port that cPanel has my RoR app running on. I also started the application via cPanel, in development mode.
If I go to mydomain.com/testblog/, I see the helpful page that lets me know that my RoR app has been created and is functioning. Great, right? Well, not so fast.
I'm following along with the Getting Started guide at guides.rubyonrails.org/v2.3.8/getting_started.html, and I get to step 4. I've run script/generate controller home index and edited the resulting view at app/views/home/index.html.erb. It's just a simple
<h1>Hello rails!</h1>
However, when I go to mydomain.com/testblog/home/index (with or without the trailing '/'), I get a blank page in my browser, nothing at all (View Source shows nothing).
To make sure that I'm not going crazy, I put a text file in my rails app's /public directory, and when I go to mydomain.com/testblog/test.txt, it gets served properly. So I know that the Apache rewrite from cPanel is working properly.
Any ideas? I figure I'm overlooking something that's obvious, but I'm drawing a blank for now.
For reference, I'm running on cPanel 11, Ruby 1.8.7 and Rails 2.3.8. I would love to be running Rails 3.0, but the shared host says it's a no-go for now.
edited to add:
Generating the home controller and index action above added the following lines to my routes.rb file (I've checked, they're there):
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
so mydomain.com/testblog/home/index should map to app/views/home/index.html.erb.
Edited again with more investigation details:
I found something that may shed some light on this. If I stop the rails app in cPanel, then log in via PuTTY and start the dev server with script/server and execute
curl http://0.0.0.0:3000/home/index
the dev server does respond with
<h1>Hello Rails!</h1>
from app/views/home/index.html.erb. So it's working there. It's when I start the Rails app in cPanel (which tells me its running on port 12002) that I get an empty response from mydomain.com/testblog/home/index. I also get an empty response from
curl http://0.0.0.0:12002
if I run it via SSH on the server. So it looks like something screwy with cPanel, not with Rails.
Did you make sure and delete your index.html file in the app/public directory of your app?
Also, after generating the home controller, did you setup your routes.rb to recognize the new controller and action?

How can I prevent cache/cookies from affecting the path of ckeditor javascript files in a production rails app?

I have a built a rails app in which I am using the ckeditor 3.5.1 together with the ckeditor gem.
When running in development, everything works fine. But when I run in production, I get errors.Sometimes, the text_area with the ckeditor does not show up. But when I clear my cache and cookies, everything works fine. Then after a while, the error comes up again. The error comes up more often than not.
Closer investigation reveals that when the error occurs, some files like staging.domain.com/javascripts/ckeditor/config.js are instead being requested from staging.domain.com/posts/config.js which is naturally non-existent
(posts is from my Post model)
How can the cache/cookies affect which path the files are served from?
Does anyone know what else might be wrong and how I can fix it?
P.S. I am using Phusion passenger in production.
It would seem the problem was being cased by mod_pagespeed which was activated. By disabling it, everything came back to normal.
I am curious though, about how this was happening.

Routes not resolving in Production Environment (Rails 2.3.5)

I'm deploying my app to a live server running passenger on Apache. I've tested the app locally and my routes appear sound. I have my public controllers under app/controllers/content and my admin controllers under app/controllers/admin.
Despite everything working in the development environment i'm getting "The page you were looking for doesn't exist." error when I request http://mydomain.com/content/compare. (i.e. Content::CompareController#index).
My production log contains the lines:
Processing ContentController#compare (for 86.40.236.34 at 2010-08-14 15:03:15) [GET]
Authentication: session found, user_id is set
ActionController::UnknownAction (No action responded to compare. Actions: ):
I've called rs.recognize_path 'content/compare' and I get the error:
ActionController::RoutingError: No route matches "content/compare" with {}
The same command works with my development machine however. I've tried adding the line
map.connect 'content/:controller/:action' to the routes config file but this doesn't have any effect and I don't think it would be useful in the long run either.
Any advice on this? Seems strange that there are inconsistences between the Rails Environments.
Thanks in advance for any help,
Can we see your routes.rb file?
It appears that on your production machine it is trying to call the compare method in ContentController. Is this the method you want to be calling or is it index?
My guess is there is something wrong in your routes file. You can compare it on both environments by running rake routes.

Resources