Forum: Ruby on Rails Unable to get past Tutorial 1 in RubyOnRails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ling (Guest)
on 2006-05-07 21:16
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/rail...
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"}
cyx (Guest)
on 2006-05-07 22:25
the error basically means that the category is nil (i.e.
cookbook.nil.name)

hope this helps.
Curt H. (Guest)
on 2006-05-08 07:32
(Received via mailing list)
Yes, this is correct. Go look at your recipes table and make sure that
every
recipe has an assigned category.

Curt
Ling (Guest)
on 2006-05-08 07:34
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.
Ling (Guest)
on 2006-05-08 07:41
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
Ling (Guest)
on 2006-05-08 09:19
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.
This topic is locked and can not be replied to.