started rails server, now what? - ruby-on-rails

I'm new to ruby on rails and trying to start learning. I'm developing on mac os x. I updated rubygems and rails.
I've started the server and have gotten the rails welcome page but my terminal is hung up. If i quit the terminal the server ends. Here is the text in my terminal right now. the cursor is on a new row directly under the last line so anything i type doesn't do anything if entered(except go to new line).
Is there a command i'm missing to start creating controllers and views in the terminal?
Last login: Thu Dec 15 18:11:43 on ttys000
You have mail.
Joe-Blows-MacBook-Pro:~ joeblow$ cd desktop/code/blogg
Joe-Blows-MacBook-Pro:blogg joeblow$ rails server
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-15 18:26:35] INFO WEBrick 1.3.1
[2011-12-15 18:26:35] INFO ruby 1.8.7 (2010-01-10) [universal-darwin10.0]
[2011-12-15 18:26:35] INFO WEBrick::HTTPServer#start: pid=25823 port=3000
Started GET "/assets/rails.png" for 127.0.0.1 at Thu Dec 15 18:26:39 -0600 2011
Served asset /rails.png - 304 Not Modified (1ms)

When developing Rails applications, you'll typically have several terminals open at once.
This terminal is just for watching the standard output logging from the server. You'll probably want another terminal open with tail -F /path/to/logs/logs to see all the logs at once, and another terminal open for your editing, rails generate ..., git, etc. uses. You might have one more open for script/console to give you an irb-alike interface "inside" your application.

Open your browser and go to http://127.0.0.1:3000
If you want to be able to use the console run
rails server &

Related

In rails with action cable. Subscription class not found "AsdfChannel". (But that's a channel from an old project!)

When I make a fresh program
~/myrubythings$ rails new channeltest3
....
~/myrubythings$ cd channeltest3
~/myrubythings/channeltest3$ rails generate channel cvbnm
Running via Spring preloader in process 2837
create app/channels/cvbnm_channel.rb
identical app/assets/javascripts/cable.js
create app/assets/javascripts/channels/cvbnm.coffee
~/myrubythings/channeltest3$ rails s
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.5.0-p0), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
Started GET "/cable" for 127.0.0.1 at 2019-04-21 02:15:56 +0100
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2019-04-21 02:15:56 +0100
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Subscription class not found: "AsdfChannel"
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2019-04-21 02:16:00 +0100 ===
- Goodbye!
Exiting
Notice I get this message Subscription class not found: "AsdfChannel"
~/myrubythings/channeltest3$ grep -irl asdf ./
.//log/development.log
~/myrubythings/channeltest3$
~/myrubythings/channeltest3$ grep -i asdf log/development.log
Subscription class not found: "AsdfChannel"
~/myrubythings/channeltest3$
The only file in this brand new project that even mentions AsdfChannel is the log file of the server!
It is picking up a channel from a project I was working on previously (channtest2)
~/myrubythings/channtest2$ grep -irl AsdfChannel ./
.//app/assets/javascripts/channels/asdf.coffee
.//app/channels/asdf_channel.rb
....
But my current project (channeltest3), has no mention of AsdfChannel, or asdf_channel.rb
I checked Subscription class not found 'MyChannel' in ActionCable and it mentioned to check that the channel's rb file is in app/channels (as it should be) and not a subdirectory of it. And it is in app/channels.
~/myrubythings/channeltest3$ ls app/channels/
application_cable cvbnm_channel.rb
~/myrubythings/channeltest3$
Why would my server log be even mentioning a channel from a previous project. Should it be? And how can I properly kill off the channel from my previous project so that my new project doesn't mention it?
By the way, it doesn't stop me from broadcasting from server to client (from the channel of my current project, when I add code to do so), but that message I get still seems like a strange error to me.
It turns out that I had a tab open from an old project that used actioncable and even though I had closed the server, and started a new tab for the current running server, the old tab being open was still having an effect.
The solution was to close all the tabs I had open that were at 127.0.0.1:3000, and only open such a tab/tabs after the server starts.

Why does my WEBrick server get killed?

I've got a rails development environment running in DigitalOcean on Ubuntu 12.04, but my WEBrick process keeps getting "killed" after a couple of hours. I haven't been able to find any settings or configuration that would cause this.
Example Console Ouput:
user#machinename:~/git/app$ rails s
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2014-01-05 09:14:29] INFO WEBrick 1.3.1
[2014-01-05 09:14:29] INFO ruby 2.0.0 (2013-11-22) [x86_64-linux]
[2014-01-05 09:14:29] INFO WEBrick::HTTPServer#start: pid=23452 port=3000
Started GET "/" for x.x.x.x at 2014-01-05 09:14:37 +0000
Processing by FunController#welcome as HTML
...
The server and app run just fine when I'm using it. But, at some point, my server will quit working. And, I'll look at the console to see this output from WEBrick:
Killed
And kick me back out to the shell. Any ideas what is causing this?
It runs out of memory. The linux kernel kills it. Droplets don't come with any 'swap' by default, so when the memory gets full, it kills a process or won't let you start a new one. Kinda crazy.
Here's an article walking you through adding a swapfile:
https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04
Note: I still had some problems with compiler processes being 'killed' even after adding a swapfile when 'swappiness' was set to 0. Upping it to 20 fixed the problem.
Note2: You really shouldn't use webrick in production as others have mentioned in the comments. Still, a question is a question :)

Aptana Studio: A server is already running error

Sometimes when I boot up my computer then open up Aptana Studio for Rails, then try to start my server, I get the following error...
=> Booting WEBrick
=> Rails 3.2.11 application starting in development on http://localhost:3000
=> Call with -d to detach
A server is already running. Check C:/Users/bob/bob_rails_demo/Course_Stats/tmp/pids/server.pid.
=> Ctrl-C to shutdown server
Exiting
When I check that file metioned, I open the file and all it says inside the file is ...
512
Is there a fix for this? I don't see anything else running in task manager. BTW I am running rails 3.2.11 w/ Windows 7.
I have the same problem too, and it didn't happen before, so i believe it is some kind of bug. What I do to solve it is simply delete the server.pid at C:[pathToApp]\tmp\server.pid file before starting my server.
It is saying that PID (process id) 512 is running the server.
Go to Start -> then type taskmgr.exe. Then, go to the processes tab and look for that process and kill it. It might be a bug that it does not close the server correctly on exit.

Rails Server is not finishing inside terminal

I am new to Rails and working my way through RonR3 Tutorial. Everything has worked perfectly except by page 59
$ rails generate scaffold Micropost content: String user_id:integer.
When I try to run rails s or rails server my terminal application never seems to end. When I ctrl-c to shut down the server after 10+ hours the site can not be found on localHost. Any help would be much appreciated.
Everything seems to stall out around:
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2012-09-20 13:33:54 -0400
Served asset /users.js - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-09-20 13:33:54 -0400
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
After this the terminal just sits there doing nothing...
With programs run from the terminal, they will run there unless they stop or have a daemon option. When you press ctrl-c, the rails webbrick server stops, so of course localhost won't show anything.
When the server is sitting there, it's waiting for a user to visit the site. It won't render views, for example, unless there's a request to render views.
If you want to run the webserver while still using the same terminal window, you need to run rails s as a daemon (background process). Instead, run the command as rails s -d which will "detach" the server process.
On a side-note, why not open multiple terminal windows, if your operating system has a GUI/Window Manager. I normally keep three terminal windows open to run the server, make git commits, check rake routes, etc.
Related Question: Running Webrick server in background?

Setting up rails - 304 Not Modified

I am newbie trying to learn some code. I am following the tutorial on http://guides.rubyonrails.org/getting_started.html
I am up to the point where I've gotten the welcome aboard message at localhost:3000, the last command I typed into my OSX terminal was "rails server"
The server spit out some info and at the end I got this...
Started GET "/assets/rails.png" for 127.0.0.1 at Fri Jan 27 12:44:36
-0500 2012 Served asset /rails.png - 304 Not Modified (2ms)
Started GET "/assets/rails.png" for 127.0.0.1 at Fri Jan 27 12:48:29
-0500 2012 Served asset /rails.png - 304 Not Modified (0ms)
Now the terminal prompt is not coming up...not sure how to fix or what I should do? Thanks to anyone who can help!
When you type in rails server (or rails s for short) the server starts running in that terminal window. This is a good thing. It means that there was no critical error at start up and rails will proceed by showing you a log of what's happening in your app - what resources it's serving, how long does it take, what views is it rendering, what database queries is it running, etc.
To proceed you can either kill the server by pressing control-C or simply open up a new terminal tab by pressing command-T and work from there and you can always switch to the first tab to look at the log if needed. With rails you usually don't need to restart the server so you can usually just keep it running in a tab in your terminal (an exception to that is when editing stuff in config or your Gemfile).
The server runs until you end it by typing Control+C. What it does is turns your computer in to a web server, and allows you to look at your website by going to http://localhost:3000 (by default this is the webport). There is nothing wrong with your computer or program. The server will show you a log of what it's doing while you navigate your website.
The 304 Not Modified is just telling you that when it went to fetch something, it knows it's done it before and the file was not modified. This is usually true of static assets, like images.

Resources