Rails + Passenger removing controller name - ruby-on-rails

I have picked up a legacy Rails app that uses Apache + Passenger.
The app has no documentation for me to work with.
When I run the application and hit a URL like so:
http://app.local:3000/groups/group-name
It will hit the show action in the groups controller. However when I run the app on Apache + Passenger and hit the same URL:
http://app.local/groups/group-name
It will actually tries to load the following URL:
http://app.local/group-name
From the log it has this:
Started GET "/groups/group-name" for 127.0.0.1 at 2012-12-19 03:28:44
+0000
ActionController::RoutingError (No route matches "/group-name"):
It is a total long shot and sorry to not provide anymore information but does anyone know why this would be happening and any suggestions of where to look?
I have checked the http.conf and it has no rewrite rules or anything. Just a standard http.conf for Passenger + Rails.
Any help or suggestions would be appreciated.
Thanks
Tony

Related

Strange unknown POST request repeatly to Rails app

I have my app run in production mode recently and realize in production.log that there are so many POST '/' request to my app URL. From the production.log files, I see that those POST requests come every 2 minutes.
The error in the log file looks like this...
F, [2019-09-10T19:45:13.948722 #28016] FATAL -- : [d0a8aada-89cf-495c-b7ae-c996ca3b7595]
[d0a8aada-89cf-495c-b7ae-c996ca3b7595] ActionController::RoutingError (No route matches [POST] "/"):
My Rails app run on Ubuntu 18 and using Nginx + Passenger.
I try find way to block suspicious IP by look into /var/log/ngix but I can't find the IP that associated to POST request. I think I miss something big.
Could you help suggest if where should I inspect to get the source of those requested POST ? Any suggestion is very appreciate, thank you.

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.

Rails Routing w/ Passenger - How to get passenger to pay attention to root route?

I have a root route setup in my app, which works fine on a local webrick server. (localhost:3000/ brings up the home page).
On my nginx/passenger server, though, it's looking for inside the public folder, and not paying attention to the route I have setup to redirect the root - so instead I'm getting a not-found error.
Any help is greatly appreciated.

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?

Resources