I have created my apps and everything is there but when I go to my host address, I cannot see anything, it gives me 404 NOT FOUND error. I also did rails server but it seems to hang. It looks like it just stops at WEBrick:HTTPSERVER#start: pid=3457 port 3000. And yes, when I ran rails server it was under the app folder.
I also went to port 3000, it says this page is not available.
When I add an index.html file, I can see that file. But this is obviously not what I want.
What else do I need to check to get to my app?
You need to configure the default route for your application, also known as root.
Add a line like this to your routes.rb file:
root to: 'newpage.html'
Or, if you want to route to a controller, like the show method on the People controller:
root to: 'people#show'
Here is the Rails guide on routing
Try to run the app in the new port as:
rails s -p 4000
Place root :to => "static#index" in your routes file and add an index file in public/.
Related
It used to be that routes.rb had a root route line. But I don't see it anymore even though when I run the server I see the "Yay! You’re on Rails!" page. I can't find where it is defined so I can override it!
On a new project it doesn't use a root route, it just renders the rails' default new project page.
Just add the line:
root to: 'somecontroller#someaction'
and you are done.
The routes.rb file is in the config/ directory of your rails project. You can define a root route there and direct it using the routes DSL
Above answers are correct but incomplete.
With Rails 6 it seems that there's no explicit root route ('/'). Instead the rails gem(s) handle it by displaying the standard "Yay you're on Rails" page (see railsties/templates/welcome/index.html.erb). It's a fixed page, bypassing routes.rb and layouts etc.
This behavior seems to only happen in development mode and when you haven't actually defined a root route.
So it seems that the page is fixed and unmodifiable. But it can easily be replaced by a root route.
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?
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
Noob Alert. I am learning RoR, have Windows 7, so I downloaded the latest BitNami stack and installed that.
Ran through the Rails guides and created my first application 'A blog' and everything worked fine.
However, I want to move on to my second rails app, but I don't know how to navigate to it. The first one was at localhost:<port>, and my routes.rb file has map.root => :controller => "home".
When I double click on the index.html file in my 'newapp/public' folder I see the 'Welcome to Rails' page that indicates that this new app was created successfully.
However when I go to localhost/newapp/index I don't see it. I get a routing error:
Routing Error
No route matches "/AddressBook/index" with {:method=>:get}
Help!
[Edit] bump Has anyone gotten a chance to look into this?
You need to change the port that the second instance runs on. In the below picture, taken from here, change the port number of the second instance from 80 to to (say) 81. Then visit localhost:81 in your browser for the second instance.
(source: moodle.org)
I assume you're starting the first server with something like this:
ruby script/server
Start the second server like this:
ruby script/server -p 3001
You can pass whatever you want instead of 3001. By default, with no -p option, it runs on port 3000.
EDIT: in response to your comment: first thing, make sure it's not a path issue. Find where that file is and make sure the enclosing folder is in your path.
If that doesn't help, I'd try doing development on SQLite instead of MySQL.
I have apache 2.2 with mod_rails running at http://localhost. I want to have my rails app at http://localhost/railsBlog. So, what I did was, I created a virtual host:
ServerName localhost
DocumentRoot /Library/WebServer/Documents
RailsEnv development
RailsBaseURI /railsBlog
Now, since the URL is http://localhost/railsBlog, the server views railsBlog as the controller I'm passing in, which is not what I want. So when I go to http://localhost/railsBlog/home/index. This won't get to my 'home' controller and 'index' view because it tries to go to 'railsBlog' controller (doesn't exist) and 'home' view (doesn't exist).
I think one way to solve this is to redefine map.root to be /railsBlog and things should be fine. But how?
Another way I could get around this would be to modify config/routes.rb to have:
map.connect 'railsBlog/:controller/:action/:id'
However, this would mean that I would have to change this file every time I deploy to a different location.
Or, is there any other way to get around this?
You can put a line like this in config/environment.rb (or one of the specific environment files)
config.action_controller.relative_url_root = "/railsBlog"
You should also symlink the publc directory to the root of the web directory, for example:
ln -s /rails/railsBlog/public /webroot/
This is all from the passenger documentation
Just to add to the previous answer... here is the url of the documentation:
http://www.modrails.com/documentation/Users%20guide.html#deploying_rails_to_sub_uri
Also, here is some information if you are running into errors with broken image, css, resource links...
http://www.modrails.com/documentation/Users%20guide.html#sub_uri_deployment_uri_fix
Basically it says you should always use the rails helper functions (image_tag, javascript_include_tag, and stylesheet_link_tag) instead of hand coding the urls. These will automatically generate the correct URL with the sub uri you have set.
This allows you to easily move the application to another sub uri or out of the sub uri configuration without changing all of your references.
One nice thing about this is that you can use one virtual server statement to deploy mutiple applications by having multiple RailsBaseURI lines. This came in handy for an app we were trying to build.