Routes not resolving in Production Environment (Rails 2.3.5) - ruby-on-rails

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.

Related

Rails params nulled when responding to csv format in production

I'm having a weird problem I cannot seem to figure out related to rails params.
I have a Controller where I permit any param. In this controller, a param (csv_type) controls which CSV file I will respond. CSV of type registration or attendance, for example.
This param is built in URL via path (e.g.: abcs_path(#abc, format: 'csv', csv_type: 'attendance') resulting in /abcs/id.csv?csv_type=attendance.
I would expect {"csv_type"=>"attendance", "controller"=>"abcs", "action"=>"show", "id"=>"45", "format"=>"csv"} but in production I get {"controller"=>"abcs", "action"=>"show", "id"=>"45", "format"=>"csv"}. csv_type is gone.
This works flawlessly locally and I get all params. Also works well on Heroku review apps. Also works well when I run locally on RAILS_ENV=production.
But in real production, it doesn't. It also doesn't work on staging which is configured with RAILS_ENV=production. Though review apps are also RAILS_ENV=production, which makes the whole thing a mystery.
Ideas:
- nginx messing up with domain (staging and production are on official domain, review app is Heroku domain, local is localhost).
- sqreen somehow intercepting this
- mime.types and https (have tried adding csv to rails, with no success). Didn't add on nginx
- some rails config on params permit (though I'm doing params.permit!) on before_action just to make sure
- some ENV variable messing up?
- can't think of anything else ???
Thanks in advance for the help!

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?

Trying to learn RoR, but keep getting Page doesn't exist errors

I'm trying to learn RoR and I keep getting pesky page doesn't exist pages. I deleted the index.html file out of my public folder and created a root route in my routes file but I still am getting that error. I am running ubuntu 10.04 with mod_passenger and ruby enterprise edition.
just leave the mod_passenger until you find the error. Do like this:
open a shell
go to your Rails app directory
ruby script/server (Rails < 3).
It should start the server in your console. and browse the page you want. If you are getting an error it should display in the console.
check your database connection is OK in config/database.yml file
rake routes is the standard shell command to see all your routes. Check if url you're trying to access is in the list. If it's not, show us statement in routes.rb you use to generate this route and url you're trying to access.
Can you please paste the content of your routes.rb file?
Also, make sure you have a controller created for that page and it should contain the index action.
def index
end

Resources