Server side programming, using the Ruby on Rails (RoR) framework help please

Hello ,

I have a home work shown below i did most of the things , i wrote
rthml and database in netbeans but i cant run

Homework and code i wrote are below what is missing here i dont know
please help . I cant run it

Implement a WEB application using the RAILS framework for maintaining
an online directory on hotels. Each entry in the directory will have
the following fields:

hotel name
city
year built
“star” classification (how many stars, integer)
home many rooms
pool (yes/no)
You will need to create a database using the meta-data given above in
either MYSQL, POSTRESQL or some other database system that is familiar
to you. The table can be created either using SQL and the interface of
your database system, or from within RoR, using migrations.

The operations that should be implemented are:

Create a new hotel
Delete a hotel
Show all hotels
Find an entry by hotel name and display it
Find and display hotels which have pools

Include pictures of hotels in the database and show them also.

RB FILE

class Assignment < ActiveRecord::Migration
def self.up
create_table : Hotels do |t|
t.coloumn : hotel_name, :string
t.coloumn : city, :string
t.coloumn : yearbuilt, :int
t.coloumn : star, :int
t.coloumn : numofrooms, :int
t.coloumn : pool, :string
end

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

Hotel.create : hotel_name => “Catamaran Resort” , city =>“Fethiye”,
yearbuilt =>“2006”,star=>“5”,numofrooms=>“860”,pool=>“yes”

Hotel.create : hotel_name => “Oasis Beach Club” , city =>“Kas”,
yearbuilt =>“2001”,star=>“7”,numofrooms=>“3600”,pool=>“yes”

Hotel.create : hotel_name => “Dedeman” , city =>“Cesme”,
yearbuilt =>“2003”,star=>“5”,numofrooms=>“450”,pool=>“yes”

end

def self.down
drop_table : hotels
end
end

class Assignment < ApplicationController
def alllist
@hotels = Hotel.find(:all)
end
end

RHTML

List of Hotels <%for Hotel in @Hotels %>
  • <%=Hotel.hotel_name %>
  • <%end%>

    On 23 May 2010 19:40, mustafacmpe [email protected] 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”

    <%for Hotel in @Hotels %>
  • <%=Hotel.hotel_name %>
  • <%end%>

    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| %>

  • <%= hotel.hotel_name %>
  • <% 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
    :slight_smile:
    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 :slight_smile: