Unable to get past Tutorial 1 in RubyOnRails


#1

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:
21:
22:


23: <%= link_to recipe.category.name,
24: :action => “list”,
25: :category => “#{recipe.category.name}” %>
26:
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”}

#2

the error basically means that the category is nil (i.e.
cookbook.nil.name)

hope this helps.


#3

Yes, this is correct. Go look at your recipes table and make sure that
every
recipe has an assigned category.

Curt


#4

Curt H. wrote:

Yes, this is correct. Go look at your recipes table and make sure that
every
recipe has an assigned category.

Curt

Hi, 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.


#5

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:

<% @recipes.each do |recipe| %>
<% if (@category == nil) || (@category == recipe.category.name)%>


Recipe

Category

Date


<%= link_to recipe.title,
:action => “show”,
:id => recipe.id %>
    <%= 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 %>

cyx wrote:

the error basically means that the category is nil (i.e.
cookbook.nil.name)

hope this helps.


#6

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 H. wrote:

Yes, this is correct. Go look at your recipes table and make sure that
every
recipe has an assigned category.

Curt