Tuesday, January 1, 2008

Biblio Another Ruby on Rails Example for SERVAGE HOSTING Testing

First of all we will need databases:
We will use "development" and "test" in our example here
In your SERVAGE CONTROL PANEL go to MySQL Databases
  1. Create new Database
  2. Name one Database biblioTest and another one biblioDev
  3. don't forget to type in a password
  4. Note all Database Connection Informations as we will need them later
In CONTROL PANEL open up Online - Filemanager
...
now go to www
(as Servage does not offer ssh you need to do the following steps externally and copy the result "biblio"-folder to the www folder and the databases contents to the databases via import-sql)

TYPE
>rails biblio
this command will create a folder named "biblio" and inside of it the following:
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create components
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create script/process
GO TO
$ cd biblio
TYPE
>./script/generate scaffold_resource Book title:string isbn:string created_at:datetime updated_at:datetime
This will create the following:
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/books
exists app/views/layouts/
exists test/functional/
exists test/unit/
create app/views/books/index.rhtml
create app/views/books/show.rhtml
create app/views/books/new.rhtml
create app/views/books/edit.rhtml
create app/views/layouts/books.rhtml
create public/stylesheets/scaffold.css
create app/models/book.rb
create app/controllers/books_controller.rb
create test/functional/books_controller_test.rb
create app/helpers/books_helper.rb
create test/unit/book_test.rb
create test/fixtures/books.yml
create db/migrate create db/migrate/001_create_books.rb
route map.resources :books
TYPE
$ rake db:migrate
If you type it here then you will receive the following error:
rake aborted!
No such file or directory - /tmp/mysql.sock
A well known error caused as until now your "biblio" don't know where to find the right database. Therefore we need to enter some database information.

GO TO
Control Panel
Online File Manager
/www/biblio/config
EDIT
database.yml
Into this YAML(TM) Template you enter all database Values so that it looks like this:

# MySQL (default setup). Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql
# On MacOS X:
# gem install mysql -- --include=/usr/local/lib
# On Windows:
# gem install mysql
# Choose the win32 build.
# Install MySQL and put its /bin directory on your path.
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
database: rorbiblioDBdev
username: rorbiblioUSdev
password: DBpassword
host: mysqlxxx.servage.net

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: mysql
database: rorbiblioDBtest
username: rorbiblioUStst
password: DBpassword
host: mysqlxxx.servage.net

production:
adapter: mysql
database: bibliothek_production
username: root
password:
host: localhost
Save and Close and try again:

TYPE
$ rake db:migrate
Now the tables will get created as you can see in the output:

(in /mounted-storage/homeservage/subservage/scservage-id/www/biblio)
== CreateBooks: migrating=====================
-- create_table(:books)
-> 0.1884s
== CreateBooks: migrated (0.1885s) ==============
GO TO
Control Panel
Online Filemanager
/www/biblio/app/views/books/new.rhtml
EDIT

New book



<%= error_messages_for :book %>

<% form_for(:book, :url => books_path) do |f| %>


Title

<%= f.text_field :title %>




Isbn

<%= f.text_field :isbn %>




Created at

<%= f.datetime_select :created_at %>




Updated at

<%= f.datetime_select :updated_at %>




<%= submit_tag "Create" %>


<% end %>

<%= link_to 'Back', books_path %>
DELETE the bold Part
CHANGE "
Isbn" to "ISBN" as it will look much nicer :-)
GO TO
www/biblio/app/models/book.rb
EDIT so that it looks like this:
class Book < ActiveRecord::Base
validates_presence_of:title,:isbn
end
GO TO
www/biblio/app/controlers/book_controller.rb
EDIT and CHANGE line 5 to:
@books = Book.find(:all,:order=>'created_at DESC')
Now our book entries will get sorted. Before saving check that there is only ONE Bracket at the End of this line ;-)

GO TO
www/biblio/config/routes.rb
CHANGE line 16 to
14 # You can have the root of your site routed by hooking up ''
15 # -- just remember to delete public/index.html.
16 map.connect '', :controller => "books"
Don't forget to remove the # at line 16!!! to enable this line

GO TO
www/biblio/public/index.html
RENAME or DELETE it

GO TO
Control Panel
Web Server
View (your Host where you want to add the subdomain "biblio")
Let's fill some data in:
$ruby script/console
Now we are in the Surrounding to insert Ruby and Rails Code
>book=Book.new(:title=>'Ruby and Rails at Servage Hosting',:isbn=>'12345678')
This creates a new book
>book.save
Saves
the Entry

Go to your site and ENJOY.

This post will be continued with some more testing later - happy new year

3 comments:

BARCHIL said...

hi,
Your Post is really good and have some good points but if you can give us more details on how to configure ROR application to work.

All the stuff you explainted and thank you again are how to create and implement ROR application .
Now we have aour application working locally
but all my work fail down when its about hosting it specially in Servage.net account ( i'm a custumer )
the first thing i had is 500 error server with no page in the browser or juste editing the content of the fcgi file .
for this i read somewhere that the problem was the version of appashe installed i fixed it
but now it give me the error We're sorry, but something went wrong.

please if you can post some info about this
Thank you ;)

GodInPerson said...

Hi,

I am getting :
MissingSourceFile (no such file to load -- mysql): in my production log.

Do you know how to solve that?

Thanks

Andreas Becker said...

Ok I access the Servage Server thru ssh!

Therefore it is much easier to configure the complete stuff. To do so I installed TYPO3 and the terminal extension and voila you can surf around on the complete clusters of servage.

Andi