Unable to get past Tutorial 1 in RubyOnRails On 29 April 2006 I met some one in a Microsoft sponsored developers? community gahering. I was told that ruby on rails is a free software, easy to use, and in no time will have my mind blown with all the wonderful prospects and possibilities. After almost a week, I am still unable to get past tutorial 1 and still unable to make any tutorials work so far. I have watched a few videos and demos from the web and I have browsed through half a book on programming ruby. I have tried http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html?page=1 Encountered some problems such as ?Port 80 for Apache was being used by some other process?, and being unable to connect to my mySql in the local host. So I switched to a newer version of the tutorial in http://instantrails.rubyforge.org/tutorial/index.html I encountered similar problems. So, I moved on to try the tutorial in the site http://rails.homelinux.org/ for 4 days on rails. I couldn?t even get into day 1, so to say. I also tried the tutorial on http://wiki.rubyonrails.org/rails/pages/Tutorial and didn?t get to point of ?Congratulations, you?re on Rails!? I browsed through the 6 part tutorials, but didn?t gained much. After that I went back to http://instantrails.rubyforge.org/tutorial/index.html Un-installed and re-installed a few times until I came to the part where ?Edit? a recipe was introduced and got stuck. So, I turned to the Forum for help, stating my problem as best I could. I was advised to look at the codes in the pre-installed ?cookbook?. I went through the processes and found that each of the step work. Since the ?Edit? part didn?t work in my exercise in ?cookbook2?, I copied the whole folder ?App? from ?cookbook? to ?cookbook2? so the codes are idential. I removed the database ?cookcook2? and used the MySQL-Front 3.2 to create a new database ?cookbook2? and check to make sure that the tables and fields resembled those of the pre-installed ?cookbook?. I was able to log into the website to create the required categories so that they wouldn?t be empty when I tried to create new recipes. Some one please help! I was able to to enter the website to create a new recipe, using http://localhost:3000/recipe/new Problem came when I pressed to ?Create? button. This brought me to the url: http://localhost:3000/recipe/list Error message: NoMethodError in Recipe#list Showing app/views/recipe/list.rhtml where line #23 raised: You have a nil object when you didn''t expect it! The error occured while evaluating nil.name Extracted source (around line #23): 20: </font> 21: </td> 22: <td> 23: <%= link_to recipe.category.name, 24: :action => "list", 25: :category => "#{recipe.category.name}" %> 26: </td> RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/app/views/recipe/list.rhtml:23 #{RAILS_ROOT}/app/views/recipe/list.rhtml:8 Request Parameters: None Show session dump Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} -- Posted via http://www.ruby-forum.com/.
the error basically means that the category is nil (i.e. cookbook.nil.name) hope this helps. -- Posted via http://www.ruby-forum.com/.
According to the given error message, my best bet is that (at least) one recipe in your database (possibly created before your database had any categories) has no category. If you really want to learn how to use Rails, I strongly suggest http://www.pragmaticprogrammer.com/titles/rails/index.html it shows how rails really works, and not just how some specific apps works.
Yes, this is correct. Go look at your recipes table and make sure that every recipe has an assigned category. Curt On 5/7/06, cyx <cyx.ucron@gmail.com> wrote:> > the error basically means that the category is nil (i.e. > cookbook.nil.name) > > hope this helps. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060508/fcbdb61f/attachment.html
Greetings. Thanks for the reply. At this stage I still don?t know enough of the syntax of ruby. Even though I have guessed that it means category or recipe is nil, I still don?t know how to resolve the problem. What puzzles me is that the codes work in ?cookbook? but not in ?cookbook2?. The same problem occurred when I tried to show the list of recipes when there were none. Isn?t it possible to display an empty list in ruby? Can some one help? Or do I need to finish reading the book ?Programming in ruby? before I can work the tutorial 1? Regards, Ling. The codes behind the module ?list.rhtml? is repordued as follows: <table border="1"> <tr> <td width="40%"><p align="center"><i><b>Recipe</b></i></td> <td width="20%"><p align="center"><i><b>Category</b></i></td> <td width="20%"><p align="center"><i><b>Date</b></i></td> </tr> <% @recipes.each do |recipe| %> <% if (@category == nil) || (@category == recipe.category.name)%> <tr> <td> <%= link_to recipe.title, :action => "show", :id => recipe.id %> <font size=-1> <%= link_to "(delete)", {:action => "delete", :id => recipe.id}, :confirm => "Really delete #{recipe.title}?" %> </font> </td> <td> <%= link_to recipe.category.name, :action => "list", :category => "#{recipe.category.name}" %> </td> <td><%= recipe.date %></td> </tr> <% end %> <% end %> </table> cyx wrote:> the error basically means that the category is nil (i.e. > cookbook.nil.name) > > hope this helps.-- Posted via http://www.ruby-forum.com/.
Thanks. Curt. I have created 3 categories before I tried to create the first recipe. I chose a category from the drop down. So there was a category for the new recipe to be created. It appears that the recipe list was empty up till then. When I pressed the "Create" button, the error message as shown appeared. The same message appeared when I tried to display the recipes when there were none. So, what is the problem? Regards, Ling Curt Hibbs wrote:> Yes, this is correct. Go look at your recipes table and make sure that > every > recipe has an assigned category. > > Curt-- Posted via http://www.ruby-forum.com/.
Ling
2006-May-08 05:20 UTC
[Rails] Unable to get past Tutorial 1 in RubyOnRails/Resolved/Thanks
Curt Hibbs wrote:> Yes, this is correct. Go look at your recipes table and make sure that > every > recipe has an assigned category. > > CurtHi, All I found my mistake in the database setting. The field "title" in the table [recipes] doesnot allow null and I set the default to [null]. Once I corrected this mistake, the application is running. Thanks for your advice that led me me to discover the mistake. Now, I can proceed to a new tutorial. Regards, Ling. -- Posted via http://www.ruby-forum.com/.