Fighting with Hello World

Hi Guys,
I’ve managed to install Ruby on Rails on Ubuntu 9.10, got it that up and
running, installed mysql as well. I use Netbeans 6.8 as the IDE, and
from there I can connect from a RoR project to the database with
JDBCMYSQL connector, no problem.

I can run the project, and get to what seems to be the default index
file in the browser, it has a button there to click that shows then the
status of the environment, I’, very happy with that.
(localhost:8080/RailsApplication6/)

However, 2 problems then occurs.
I type in localhost:8080/RailsApplication6/book/list
and it just throws an error about that that get is not defined in the
routes
That is just bizarre, since the default route in routes.rb should take
care of it right?
“No route matches with {:method=>get}”

secondly, when restart linux (reboot pc), then when I run the project
again, I land up with the page
HTTP Status 40
type Status report
message
descriptionThe requested resource () is not available.
for both
localhost:8080/RailsApplication6/
localhost:8080/RailsApplication6/book/list

It seems that I have some config somewhere wrong and I can’t seem to
figure out what. Im following the example from

I thought it should be as simple as just reading, typing and compiling,
but not so it seems.
Any pointers are welcome, thanks!

Len H. wrote:

Hi Guys,
I’ve managed to install Ruby on Rails on Ubuntu 9.10, got it that up and
running, installed mysql as well. I use Netbeans 6.8 as the IDE,

You probably want to drop that. NetBeans is a great IDE, but it’s
overkill for Rails. Rails does not really benefit from the use of an
IDE; just use a good text editor such as KomodoEdit.

and
from there I can connect from a RoR project to the database with
JDBCMYSQL connector, no problem.

I can run the project, and get to what seems to be the default index
file in the browser, it has a button there to click that shows then the
status of the environment, I’, very happy with that.
(localhost:8080/RailsApplication6/)

However, 2 problems then occurs.
I type in localhost:8080/RailsApplication6/book/list
and it just throws an error about that that get is not defined in the
routes
That is just bizarre, since the default route in routes.rb should take
care of it right?
“No route matches with {:method=>get}”

The default route is /:controller/:action , so it will try to find a
controller and action that match the URL (in this case, “/book/list”).
Unless you have a BookController (strange – normal convention would be
BooksController) with an action called “list”, you will get routing
errors.

secondly, when restart linux (reboot pc), then when I run the project
again, I land up with the page
HTTP Status 40
type Status report
message
descriptionThe requested resource () is not available.
for both
localhost:8080/RailsApplication6/
localhost:8080/RailsApplication6/book/list

It seems that I have some config somewhere wrong and I can’t seem to
figure out what. Im following the example from
Ruby on Rails - Directory Structure

Try the examples at http://guides.rails.info .

I thought it should be as simple as just reading, typing and compiling,

Ruby is not a compiled language.

but not so it seems.
Any pointers are welcome, thanks!

It should be much simpler. I suspect you’re trying to type in a URL
that doesn’t yet route to anything.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Hello Marnen,
Thank you for your thoughtful feedback.

The default route is /:controller/:action , so it will try to find a
controller and action that match the URL (in this case, “/book/list”).
Unless you have a BookController (strange – normal convention would be
BooksController) with an action called “list”, you will get routing
errors.

I had a look again.
When I create the controller I did it with Book, as the example said:
C:\ruby\library> ruby script/generate controller Book
I used the netbeans IDE and said, please create controller Book, and I
got:
book_controller.rb
which I hope is right.

Then I did the view thingy:
and created a view (aka list.rhtml)
now, if my reading skills are up to par, I should get to this by typing
in
localhost:8080/RailsApplication6/book/list
or should it be?
localhost:8080/RailsApplication6/book_controller/list

I’ve been in IT for 12 years, still it seems like getting the basics to
work is the hardest, the coding part I find dead easy when I get the
core stuff working, such as compiling hello world!

I’m going to take your advice and try your samples link.
This should be as easy as falling out of a tree… to do a simple
example.
thanks for your time.

secondly, when restart linux (reboot pc), then when I run the project
again, I land up with the page
HTTP Status 40
type Status report
message
descriionThe requested resource () is not available.
for both
localhost:8080/RailsApplication6/
localhost:8080/RailsApplication6/book/list

It seems that I have some config somewhere wrong and I can’t seem to
figure out what. Im following the example from
Ruby on Rails - Directory Structure

Try the examples at http://guides.rails.info .

I thought it should be as simple as just reading, typing and compiling,

Ruby is not a compiled language.

but not so it seems.
Any pointers are welcome, thanks!

It should be much simpler. I suspect you’re trying to type in a URL
that doesn’t yet route to anything.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I can run the project, and get to what seems to be the default index
file in the browser, it has a button there to click that shows then the
status of the environment, I’, very happy with that.
(localhost:8080/RailsApplication6/)

I’m curious about what server you are using?

Len H. wrote:

I had a look again.
When I create the controller I did it with Book, as the example said:
C:\ruby\library> ruby script/generate controller Book
I used the netbeans IDE and said, please create controller Book, and I
got:
book_controller.rb
which I hope is right.

If you are using netbeans IDE, right-click on your project → generate
→ controller

Name: books
View: index

Open up configurations → routes.rb

map.resources :books, :controller => :books, :only => :index

You can look up how resources work. There are multiple ways of doing
this here, but just start with this.

Since you are using netbeans, your view will look like such from the
IDE:

Project Name
– Controllers
---- books_controller.rb (this is your controller)
– Models
---- (none) (read note #1 below)
– Views
---- books
------ index.html.erb (this is your view template)

#1 If you specify a scaffold instead of a simple controller, you’d get a
full MVC (Model + View + Controller) for books. In addition to
books_controller.rb you’d find a book.rb in your models. Scaffolds
would be used if you are creating information to store in a database.
By default, netbeans would automatically create the map route for you in
routes.rb by placing in map.resources :books

From netbeans, right-click your project → run (this will startup your
environment).

Your page should automatically be displayed (for the root)

Go to the end of the line:

For me it’s :

http://localhost:3000/

… if for you it’s … http://localhost:8080/ that’s fine too.

http://localhost:8080/books/

Your books view should now display.

If you have any questions about netbeans, there is a great support group
in netbeans through their forums → subforum is rails at their main
site. Let me know if you have any questions.

Also, see the following link to get you started with rails and answering
most of the generic questions:

http://www.ruby-forum.com/topic/191189

On Sat, Jan 9, 2010 at 12:36 AM, Len H. [email protected]
wrote:

Curtis S. wrote:

I’m curious about what server you are using?

I’ve installed the Netbeans package that comes with Glassfish version 3,
as well as Webrick. Glassfish runs on port 8080, and Webrick on 3000.
Both gave me the same trouble, so the problem wasn’t the webserver part.

What is the output of ‘rake routes’ ?

Curtis S. wrote:

I’m curious about what server you are using?

I’ve installed the Netbeans package that comes with Glassfish version 3,
as well as Webrick. Glassfish runs on port 8080, and Webrick on 3000.
Both gave me the same trouble, so the problem wasn’t the webserver part.

Thanks Elric,
I’m going to try your suggestions out over the weekend.
Hopefully things will start coming together this side :slight_smile:
I will give feedback again.
Regards, Len.

“I type in localhost:8080/RailsApplication6/book/list”

Given that, plus your routes output, perhaps try adding a line like this
to
your config.rb file (near the top)

map.resources :books

or

map.resources :book

Not sure if it would be singular or plural for you.

Good luck.

Jason S.
“I’m going to live forever or die trying.”

Curtis S. wrote:

What is the output of ‘rake routes’ ?

(in /home/daddy/RailsApplication6)
/:controller/:action/:id
/:controller/:action/:id(.:format)

Len H. wrote:

Curtis S. wrote:

What is the output of ‘rake routes’ ?

(in /home/daddy/RailsApplication6)
/:controller/:action/:id
/:controller/:action/:id(.:format)

Then /book/list will not be routable, because it does not match either
of these patterns. However, /book/list/1 will work. Try it.

The fact that you’re asking these questions makes me think you’ve
started with a bad tutorial example. Start over with the Rails Guides,
and get rid of NetBeans. You’ll be a lot happier.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On Sat, Jan 9, 2010 at 9:02 AM, Marnen Laibow-Koser
[email protected]wrote:

of these patterns. However, /book/list/1 will work. Try it.

Yes, I have to agree with Marnen that you should use Rails Guides which
can be found here:

Good luck,

-Conrad

Here is a simple screencast that creates a scaffold using NetBeans and
runs on GlassFish:

http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug

See if this helps. This screencast was created with NetBeans 6.5 RC2 &
GlassFish v3 Prelude. And NetBeans 6.8 and GlassFish v3 are the latest
versions. But I’ve shown this demo multiple times in different talks.

Another difference is I recorded the screencast on Windows and showed
the demo on Mac and yours is Ubuntu.

See if you can have this simple sample working.

-Arun

This is a great suggestion: