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

**URL:** <https://www.ruby-forum.com/t/server-side-programming-using-the-ruby-on-rails-ror-framework-help-please/189068>\
**Category:** Rails\
**Created:** [May 23, 2010, 9:19pm UTC](https://www.ruby-forum.com/t/server-side-programming-using-the-ruby-on-rails-ror-framework-help-please/189068 "2010-05-23T21:19:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mustafacmpe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@mustafacmpe](https://www.ruby-forum.com/u/mustafacmpe)\
**Post date:** [May 23, 2010, 9:19pm UTC](https://www.ruby-forum.com/t/server-side-programming-using-the-ruby-on-rails-ror-framework-help-please/189068/1 "2010-05-23T21:19:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mustafacmpe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@mustafacmpe](https://www.ruby-forum.com/u/mustafacmpe)\
**Post date:** [May 23, 2010, 10:49pm UTC](https://www.ruby-forum.com/t/server-side-programming-using-the-ruby-on-rails-ror-framework-help-please/189068/2 "2010-05-23T22:49:15Z")

</div>

On 23 May 2010 19:40, mustafacmpe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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  
🙂  
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 🙂
