On 23 May 2010 19:40, mustafacmpe <mustafa.c...@gmail.com> wrote:
> Hello ,

Hello!

> I have a home work shown below
>
> Homework  and code i wrote are below what is missing here i dont know
> please help . I cant run it
>

Well, I'm not prepared to *do* your homework for you; if you pass the
course, and use the qualification to get a job, I doubt you'll be
sending me the pay cheque!
I would *assume* that you've been given all the info in your class to
complete the homework, so I will help you out with some of the obvious
problems so you can get it working yourself.

> class Assignment < ActiveRecord::Migration
>        def self.up
>        create_table : Hotels do |t|

There's two issues here. First, there shouldn't be a space after the
colon, and the name of the table should be with a lower case "H". So:
   create_table :hotels do |t|

>        t.coloumn : hotel_name, :string

You've misspelt "column" in all the rows, and again, there shouldn't
be any spaces after the colons.

>        Hotel.create : hotel_name => "Anatolia Beach Hotel" , city =>"Kemer",
>        yearbuilt =>"2004",star=>"5",numofrooms=>"1200",pool=>"yes"

There *should* be colons in front of those hash-keys (and again, there
shouldn't be a space after the colon). Also, you've created the fields
:yearbuilt, :star and :numofrooms as integers in the DB, but you're
assigning them as strings - Rails might sort that one for you, but
better to be correct to begin with. So:
  Hotel.create :hotel_name => "Anatolia Beach Hotel" , :city =>"Kemer",
  :yearbuilt =>2004, :star=>5,numofrooms=>1200, :pool=>"yes"


> <body>
> <%for Hotel in @Hotels %>
> <li><%=Hotel.hotel_name %> </li>
> <%end%>
> </body>
> </html>

There are some conventions in Ruby/Rails about naming objects, and one
is that if a name begins with a capital letter it is a constant. So
best not to name the variable in the loop "Hotel" (especially since
that's the class of the object too (although you've not pasted any
model code.... but you do have a "hotel.rb" file right?).
Also, your instance varable is named "@hotel" in the controller, but
you're accessing "@Hotel" here, so you would find out that the loop
won't do anything, because @Hotel is nil.
BTW, a more "Ruby" loop is to use an iterator instead of a for...each
(but that's really a personal preference):
  <% @hotels.each do |hotel| %>
   <li><%= hotel.hotel_name %> </li>
  <% end %>



That's a few issues that jump out of the code at me, and I guess there
may be one or two more. But if you sort them out and try it again, it
might run a little further.

The next thing I suggest for you is a two-pronged attack:
Firstly, when you come back and post your next message, give us some
more information about *what you did*, and *what happened*.
Saying "I cant run it" doesn't give us much to go on, but if you say
"I tried 'rake db:migrate' on my Ubuntu machine, and got a message
that the db can't be found. How do I tell Rails about my db location?"
we can answer more accurately.

Secondly, for your own personal development I would suggest
concentrating a little more on the details - give it a little more
attention.
I spotted all those problems above with one look through your code;
and I'm *sure* that if you had thought about it, you could have solved
a few of them yourself
:-)
The Rails framework is an excellent tool, but like any tool you need
to know how to use it properly to get the best results from it.
Looking at the code, I guess you didn't use Rails generators to create
a scaffolded application for you... it might be worth doing a quick
Google, and approaching it that way, as the majority of the hard work
will be done for you.

But keep plodding through your problems one at a time, and eventually
they all go, and you'll be left with lovely working code :-)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to