rails beginner, created 2 rails app on local dev - ruby-on-rails

I am new to rails and I was able to install rails (3.2.3, ruby v1.9.3), then created a test app:
$ rails new Hello
then I cd'd into the new directory 'hello' and did the following commands:
$ rails generate controller home index
$ rails s
$ rake routes, it gave me
home_index GET /home/index(.:format) home#index
hello /hello(.:format) Hello#index
Then I pointed my browser to: http://localhost:3000/home/index - and it worked great.
Then I wanted to begin a tutorial and it asked me to create a new rails application
so I did like I did before...
$ rails new TutorialApp
$ rails generate controller tutorial index
$ rails s
$ rake routes, it gave me
tutorial_index GET /tutorial/index(.:format) tutorial#index
then I pointed my browser to: http://localhost:3000/tutorial/index, it gave me a message of
Routing Error
No route matches [GET] "/tutorial/index" Try running rake routes for
more information on available routes.
So I ran rake routes again, which it gave me the same output as it did before
tutorial_index GET /tutorial/index(.:format) tutorial#index
Since I created that first rails app "Hello", do I need to turn off that app before starting the new rails app "Tutorial" or they can both be running at the same time?
Any help is appreciated, thanks!

You can use a different port
rails server -p 3001
It will run in a different port. Then, just point to http://localhost:3001
But usually you will probably stop the server on one app and start the other one. It's up to you.

When you run rails server ("rails s"), you're typically running it in the context of the rails project you're in at the time, so before beginning a new project, I would shut down the current server (CTRL C). Also, make sure you create a new rails app in a folder is isn't itself at the root of a rails app. It looks like you might have created your tutorial app inside the root of your Hello app. Sounds like those are the two main things that tripped you up.

Related

Rails application works in development but is empty in production

My Rails 4 application runs in development mode, but at production I only see an empty page.
It's running Unicorn with Nginx in a CentOS 7 VPS.
Any hint what I need?
unicorn_rails -c config/unicorn.rb -D
unicorn_rails -c config/unicorn.rb -D -E production
The logs of Nginx, Unicorn and Rails don't show any errors.
Rake routes
[root#mycentos my_app]# rake routes
Prefix Verb URI Pattern Controller#Action
blogs GET /blogs(.:format) blogs#index
POST /blogs(.:format) blogs#create
new_blog GET /blogs/new(.:format) blogs#new
edit_blog GET /blogs/:id/edit(.:format) blogs#edit
blog GET /blogs/:id(.:format) blogs#show
PATCH /blogs/:id(.:format) blogs#update
PUT /blogs/:id(.:format) blogs#update
DELETE /blogs/:id(.:format) blogs#destroy
In development I can access normally to any route, even it shows me error messages when the route doesn't exist. But in production, is always blank.
After investigating a lot, the problem was that there wasn't the secret key for production. So I had to generate it running rake secret and pasting it in config/secrets.yml.
I'm not so boldly switching over to the answer area here, but it's time. I know that node.js can be used to create a single page app on Rails. It's something I want to try, but haven't done, yet.
Before diving into an isolate and conquer scenario, have you looked at your production log. It will probably be stacked up with errors. Do they tell you anything?
I approach this not knowing exactly the complexion of the problem. And, I don't know what you've already tried. But, I would try to isolate the problem by removing components and complexity. I suggest creating a very simple "Hello world" page at the root. That's it. If we can resolve this and get something to deploy, then you can progress.
Getting a "Hello world!" page will prove your MVC code base setup and deploy are functioning. And you isolate the database out as a variable in production.
Hello world! Simple test - I have not seen a Rails app which did not require a root_url. (maybe node.js setup does not req. one? Dunno.) In your routes.db add
root 'static_pages#home'
Rake in and make sure the path shows up. Create an home.html.erb in /static pages that has html for "Hello World." Deploy + test to dev + prod using the same command you've been using:
unicorn_rails -c config/unicorn.rb -D -E production
If working, then you know that your deploy works, If not working in production, then remove another component...
Unplug Node.js
In your simple "Hello Page" world app, you don't need node.js. If you are 100% confident it can't be introducing the problem, then disregard this advice.
Hello world, Still not working without database and without node.js? Look at production parameters, Gemfile, etc.
I'll add detail here if needed. Although I hope the problem isn't in the environments/production.rb...but it could be.
It would seem like someone with Rails exp. on node.js would be better to answer this question, but since no one else is stepping up, I hope my input is of some help, if only to see the problem in another way.

Nitrous.IO -- Only able to Preview Default webpage

It was fairly easy to get things set up for the RubyonRails environment in the Nitrous.IO box, but I am having problems with Preview (the browser utility on the site) to see the apps that seem to be running with the $ rails server command.
My installation shows I have the following installed:
- ruby 2.1.1p76
- Rails 4.1.0
- git version 2.0.0
- SQLite3
When I try to 'Preview' the application running on WEBrick,
I get a default webpage, which says,
Routes are set up in the config/routes.rb
running in development mode and haven't set a root route yet.
I checked the config/routes.rb file in the Nitrous.IO IDE,
and it has the following:
Rails.application.routes.draw.do
resources :comments (from $ rails generate scaffold comment post_id:integer /
body:text [this was second of two commands] )
resources :posts ( $ rails generate scaffold post title:string body:text /
[this was run 1st of these two commands] )
( post and comment database tables created with: $ rake db:migrate )
# lines 6 -> 59 are comments giving coding examples of routes)
end
Any idea on what I need to do in order to 'Preview' development apps ??
Perform the Preview 3000.
You get standard info that app is running
In the browser's address bar add "/(the route you need)" (well without quotes).
In my case it looks like this:
http://blog-137119.euw1-2.nitrousbox.com/comments#index
The "comments#index" was the route I needed.
HTH
/Jacek

Cannot start project in rails

I'm pretty new to Rails.
I created a new Rails app: rails new app_name, and ran rails server etc.
But, once I shut down and reopened my machine, I can run neither rails server nor rails console. It says to use the rails new app_name command again, but I just want to restart where I left off the day before.
Any advice is very much appreciated.
I'm guessing your current working directory of your command line is not in your project directory which you created yesterday.
cd some_path/to_my/rails_project
rails server
You must be in the directory that represents your project to do things like launch the server. Otherwise, how does it know what project to launch a server for?
Just make sure you are in the directory of the rails app you created. Sounds like you aren't.

Running Ruby on Rails from subdomain

I must be missing something, but RoR is just not working for me at all. I have RoR installed where I am hosting, and I have done all of the following:
cd ~
rails rubyonrails
ln -s rubyonrails www/rubyonrails/rails
Added to rubyonrails/public/.htaccess
RailsBaseURI /rubyonrails
Then:
cd rubyonrails
script/generate model User
script/generate controller User list
When I go to http://rubyonrails.truthanduntruth.com/rails/ it seems like it's just not running RoR at all. This might have to do with the fact that I'm using the subdomain. I set up the subdomain with cpanel, so I'm not sure how it's done. The subdomain folder itself is in /home/public_html/rubyonrails
So you can also go to http://truthanduntruth.com/rubyonrails/rails/ . Instead this gives me an error page. This is no better. Based on the error page or my steps above, can anyone tell what I am missing or where I am going wrong?
I'd like to at least get RoR running at all so I can learn it, but preferably I want it to run under the subdomain.
Thanks.

Rails on remote Apache server not displaying index.html.erb

I played around with Rails on my laptop (running Linux + Apache + MySQL) and had no trouble getting the Getting Started with Rails tutorial to work locally. Now I'm trying the same thing at work on a remote Mac OS X + Apache server, and things aren't quite so rosy.
I typed rails blog -d mysql to create a directory called blog in /Library/WebServer/Documents/mydirectory. The trouble is, if I go to server.com/mydirectory/public, I get the public/index.html in my browser. But, I don't get this file if I go to server.com/mydirectory/. Instead, I get a 403 error. Also, when I:
script/generate controller home index
to create:
app/views/home/index.html.erb
I am unable to view this file, whether I go to server.com/mydirectory/home/index, or if I add a new line (map.root :controller => "home") to config/routes.rb and go to server.com/mydirectory.
Am I missing something really obvious about Apache and Rails?
Apache does not support Rails out of the box. You have to get mod_rails aka Passenger installed. Or, you could just use the server that comes with Rails, which is much easier (but not suitable for production). To do this, go to your directory and do ./script/server.

Resources