Newbie Help: Agile Rails book's Hello World

Hello everyone,

I've just recently started learning Rails and have searched this forum to try and find an answer with no luck to this seemingly simple issue. I'm hoping someone out there might be able to help me get on the right track - so far it's been days just getting through the installation process on Mac 10.4 to the point where everything appears to work on the surface.

First of all, what I'm attempting to do is to go through the book Agile Web Development with Rails 2nd ed., from the beginning, to refresh everything. I'm up to page 36 and already I've hit a roadblock. Here's my steps:

1. ran "rails -d mysql test3app" to generate a new app. 2. ran "script/server" in the new directory. 3. ran "ruby script/generate controller Say" as instructed on page 36 of the Agile book. 4. Confirmed localhost:3000 was running in the browser and everything looks good. Got this output about my app:

Ruby version 1.8.6 (i686-darwin8.11.1) RubyGems version 1.0.1 Rails version 2.0.2 Active Record version 2.0.2 Action Pack version 2.0.2 Active Resource version 2.0.2 Action Mailer version 2.0.2 Active Support version 2.0.2 Application root /usr/local/src/test3app Environment development Database adapter sqlite3 Database schema version 0

5. Edited say_controller.rb to read the following:

class SayController < ApplicationController def hello end end

6. Pointed browser at http://localhost:3000/say/hello and got the following:

Routing Error No route matches "/say/hello" with {:method=>:get}

Was expecting:

Template is missing Missing template script/../config/../app/views/say/hello.rhtml (or .html.erb)

Any ideas?

These steps appear to work fine if I use Locomotive. However, I wanted to install everything from source so I'd have the latest version and benefit from all the great new stuff. I just can't figure out why this should be a problem in Rails 2 and fine in Locomotive's Rails v.1.2.x. So perhaps I did something wrong during the installation process, I have some ridiculous typo that I'm missing, or else there is some new way of writing a controller in Rails 2 that I'm not aware of. I've looked all day for an answer so here's to hoping someone can help me out here!

And happy new year everyone!

Cheers, Joe

Hello everyone,

I've just recently started learning Rails and have searched this forum to try and find an answer with no luck to this seemingly simple issue. I'm hoping someone out there might be able to help me get on the right track - so far it's been days just getting through the installation process on Mac 10.4 to the point where everything appears to work on the surface.

First of all, what I'm attempting to do is to go through the book Agile Web Development with Rails 2nd ed., from the beginning, to refresh everything. I'm up to page 36 and already I've hit a roadblock. Here's my steps:

1. ran "rails -d mysql test3app" to generate a new app. 2. ran "script/server" in the new directory. 3. ran "ruby script/generate controller Say" as instructed on page 36 of the Agile book. 4. Confirmed localhost:3000 was running in the browser and everything looks good. Got this output about my app:

Ruby version 1.8.6 (i686-darwin8.11.1) RubyGems version 1.0.1 Rails version 2.0.2 Active Record version 2.0.2 Action Pack version 2.0.2 Active Resource version 2.0.2 Action Mailer version 2.0.2 Active Support version 2.0.2 Application root /usr/local/src/test3app Environment development Database adapter sqlite3 Database schema version 0

5. Edited say_controller.rb to read the following:

class SayController < ApplicationController def hello end end

6. Pointed browser at http://localhost:3000/say/hello and got the following:

Routing Error No route matches "/say/hello" with {:method=>:get}

Was expecting:

Template is missing Missing template script/../config/../app/views/say/hello.rhtml (or .html.erb)

Any ideas?

These steps appear to work fine if I use Locomotive. However, I wanted to install everything from source so I'd have the latest version and benefit from all the great new stuff. I just can't figure out why this should be a problem in Rails 2 and fine in Locomotive's Rails v.1.2.x. So perhaps I did something wrong during the installation process, I have some ridiculous typo that I'm missing, or else there is some new way of writing a controller in Rails 2 that I'm not aware of. I've looked all day for an answer so here's to hoping someone can help me out here!

Yes, that was the next step in the book and I did try that - created hello.rhtml inside app/views/say/. Tried hello.html.erb too. Neither one made any difference and I'm still stuck on the routing error. I was *hoping* I would see the template error without the view template but can't even get that far.

-Joe

Hi Joe, try restarting you server.

Good luck,

-Conrad

Well that did the trick. Thank you very much Conrad! Such a simple thing. So I'm now curious why the restart was required - but no big matter. It works now and I can add items to my controller now with no problems. And now I know a little more about this framework.

Now I can enjoy my new year's eve... :wink: A toast to everyone!

Cheers, Joe

If I may take you on a tangent: subversion, http://svnbook.red- bean.com/ , you only need the first few bits. I have found it quite helpful to learn enough subversion to use http://code.google.com/ for a project.

Subversion pros:

I'm going through the same book myself except I'm running things on Windows Vista.

I had exactly the same problem and had to restart the Mongrel web Server.

Thanks!

Joe Lewis wrote:

If using Rails 3.0 then before restarting server with "rails server" edit "config/routes.rb", and uncomment the following line:

match ':controller(/:action(/:id(.:format)))'

then restart server

THIS WAS AMAZING. THANK YOU SO MUCH.

Why does no one say anything about this anywhere else?! Thanks neels!

To answer a previous question, that being, "why do you have to restart the server after editing the routes", the reason is because the file config/routes.rb is read when the server loads, and its information stored in memory. The application doesn't want to re-load the routes file for every request because it just adds overhead, making it take more time (we're talking fractions of a second, but that adds up significantly over several thousand users) to process a request.

As far as your point of taking advantage of all the cool new stuff, just to let you know, Rails v. 2.x is basically outdated now. Rails 3.0 was released just a few weeks ago (prior version was 2.3.9) and has a LOT of new stuff - relationships are different (see "Arel" or "ActiveRelation" - same thing), the database agnosticism has different ways for doing queries (see "ActiveRecord" version 3), routing is very different (config/routes.rb as above), and so on.

Given that you're just starting out, you can install the 2.x series of Rails as you have above and get along fine - it'll make a lot more sense as you're moving along with the book. But just remember that the latest and greatest is already a full version release ahead of the book. This is one major reason I usually don't bother buying books on anything related to Ruby - the community moves way too fast for a book to be relevant, and usually breaks - quite unabashedly - backwards compatibility in doing so. This isn't so much a criticism as an observation, by the way.

Also, to the points about Subversion above - all the points apply to most modern source control systems and aren't unique to Subversion. SVN is pretty awesome and I've been a fan of it for years (so this is in no way meant as a "slam" to the original author for mentioning it, only an elaboration on it), but the "cool kids club" these days seems to prefer a tool called "git". The Ruby community seems to be very "populist"/teen-girl in its behavior on what tools are considered "best of breed" at any given moment. I swear to God it reminds me of junior high - when brand X was popular but you were considered a leper if you used brand Y. Rewind to 2006 or so and Subversion was all the rage. Today it's git. Three years from now, who knows. I don't buy the whole "git > svn > perforce > cvs" etc. arguments as a whole unto themselves - you just need to understand that there are different tools that work better or worse than another in a given situation (that being, your workflow), and there are other constraints to consider in the reality of a multi-user, usually corporate or somewhat- mature start-up like environment, where you can't go dicking with server configs and all the "new shiny" stuff three times a day - you eventually have to actually get work done, too.

Just thought I'd elaborate on those points to give you some more information on the general direction of things :slight_smile: Linkage incoming:

Git: http://git-scm.org/ Subversion: http://subversion.apache.org/ Rails Guides - an excellent supplement to the book: http://guides.rubyonrails.org/

Good luck man!

Wyatt R. wrote in post #949730:

If using Rails 3.0 then before restarting server with "rails server" edit "config/routes.rb", and uncomment the following line:

match ':controller(/:action(/:id(.:format)))'

then restart server

THIS WAS AMAZING. THANK YOU SO MUCH.

Why does no one say anything about this anywhere else?! Thanks neels!

Many thanks