Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

This is a discussion on Ruby on Rails: To get started in the General Hosting and Network Support forum
To start a project in Ruby on Rails, you need to login first to your account via ssh. Once you are logged in, let's see ...

  1. #1
    CTO JPC-Masood's Avatar
    Join Date
    Aug 2002
    Location
    Jaguar Servers
    Posts
    2,070

    Jpc Icon Ruby on Rails: To get started

    To start a project in Ruby on Rails, you need to login first to your account via ssh. Once you are logged in, let's see where we are located:
    [~]# pwd
    /home/masood
    Ok, we are in our home directory (otherwise cd ~). Let us start a project called guestbook.
    [~]# rails guestbook
    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
    create test/fixtures
    create test/functional
    create test/mocks/development
    create test/mocks/test
    create test/unit
    create vendor
    create vendor/plugins
    create Rakefile
    create README
    create app/controllers/application.rb
    create app/helpers/application_helper.rb
    create test/test_helper.rb
    create config/database.yml
    create config/routes.rb
    create public/.htaccess
    create config/boot.rb
    create config/environment.rb
    create config/environments/production.rb
    create config/environments/development.rb
    create config/environments/test.rb
    create script/about
    create script/breakpointer
    create script/console
    create script/destroy
    create script/generate
    create script/performance/benchmarker
    create script/performance/profiler
    create script/process/reaper
    create script/process/spawner
    create script/process/spinner
    create script/runner
    create script/server
    create script/plugin
    create public/dispatch.rb
    create public/dispatch.cgi
    create public/dispatch.fcgi
    create public/404.html
    create public/500.html
    create public/index.html
    create public/favicon.ico
    create public/robots.txt
    create public/images/rails.png
    create public/javascripts/prototype.js
    create public/javascripts/effects.js
    create public/javascripts/dragdrop.js
    create public/javascripts/controls.js
    create doc/README_FOR_APP
    create log/server.log
    create log/production.log
    create log/development.log
    create log/test.log
    Now we create a symbolic link to the public directory of our guestbook application from our web root:

    Code:
    [~]# cd public_html/
    [~/public_html]# ln -s ../guestbook/public guestbook
    Now let us see what we have on our site by visiting http://www.yourdomain.com/guestbook/

    NOTE: Replace "yourdomain.com" with your account domain.You can not access it from server IP/domain or temporary URL. You need to access it using your domain name.

    Most of the information on the default index.html is not for you, so you can ignore it. However, if you are an advanced Ruby on Rails programmer, you may probably tweak something on your own.

    Let us now generate a controller for our guestbook application. Say MyTest.

    Code:
    [~]# cd ~/guestbook
    [~/guestbook]# ruby script/generate controller MyTest
          exists  app/controllers/
          exists  app/helpers/
          create  app/views/my_test
          exists  test/functional/
          create  app/controllers/my_test_controller.rb
          create  test/functional/my_test_controller_test.rb
          create  app/helpers/my_test_helper.rb
    Now visit http://www.yourdomain.com/guestbook/MyTest

    That would bring result

    Unknown action
    No action responded to index
    Rails tried to find a default action named index in this controller but we have not defined it yet. Let us do that:

    Code:
    [~/guestbook]# vi app/controllers/my_test_controller.rb
    The file will have this:

    Code:
    class MyTestController < ApplicationController
    end
    and we add these bold lines in between:

    Code:
    class MyTestController < ApplicationController
            def index
                    render_text "Hello World"
            end
    end
    Save and quit, and then refresh the browser. Viola! you can see the new index method. You can also access it using http://www.yourdomain.com/guestbook/MyTest/index

    Let us define another method called jaguarpc

    Code:
            def jaguarpc
                    render_text "Jaguar Technologies provides high quality, reliable hosting solutions at prices anyone can afford."
            end
    and access it using http://www.yourdomain.com/guestbook/MyTest/jaguarpc

    Now we get back to our guestbook application. The above was just to get you started on rails. First we need to create a database for the guestbook. Please login to your control panel:

    http://www.yourdomain.com:2082/

    and create the database, its user/pass and grant privileges to the user over the db. Please note down the db name, db user and its password.

    Now to tell the Rails to find this database, we edit the file:

    [~/guestbook]# vi config/database.yml
    In that file we need to define three db connections for three level of dbs. For now we use same connections for all three:

    Code:
    development:
      adapter: mysql
      database: USER_db
      host: localhost
      username: USER_dbuser
      password: ****
    test:
      adapter: mysql
      database: USER_db
      host: localhost
      username: USER_dbuser
      password: ****
    production:
      adapter: mysql
      database: USER_db
      host: localhost
      username: USER_dbuser
      password: ****
    Rails lets you run in development mode, test mode, or production mode, using different databases. This application uses the same database for each.

    Our application will hold guestbook entries, so let us create a table to hold them. Please visit phpMyAdmin from your control panel and create a table called "entries".
    Code:
    CREATE TABLE `entries` (
    `id` INT NOT NULL AUTO_INCREMENT ,
    `name` VARCHAR( 50 ) NOT NULL ,
    `comments` TEXT NOT NULL ,
    `date` DATE NOT NULL ,
    PRIMARY KEY ( `id` ) 
    ) TYPE = MYISAM ;
    Now we need to create an Entry model class that will hold data from the entries table in the database.

    Code:
    [~/guestbook]# ruby script/generate model Entry
          exists  app/models/
          exists  test/unit/
          exists  test/fixtures/
          create  app/models/entry.rb
          create  test/unit/entry_test.rb
          create  test/fixtures/entries.yml
    Now if you see the model, it is an empty class:

    Code:
    [~/guestbook]# cat app/models/entry.rb
    class Entry < ActiveRecord::Base
    end
    This empty class definition is the entry business object that Rails maps to the entries table (Rails is pretty smart in English language to figure that out). Let us add controller for it:

    Code:
    [~/guestbook]# ruby script/generate controller Entry
          exists  app/controllers/
          exists  app/helpers/
          create  app/views/entry
          exists  test/functional/
          create  app/controllers/entry_controller.rb
          create  test/functional/entry_controller_test.rb
          create  app/helpers/entry_helper.rb
    Let us add some functionality to it:

    Code:
    [~/guestbook]# vi app/controllers/entry_controller.rb
    class EntryController < ApplicationController
            scaffold :entry
    end
    This single line of code will bring the database table to life. It defines actions for all CRUD operations, immediately allowing us to create, read, update, and delete entries in our database! Now visit http://www.yourdomain.com/guestbook/entry and enjoy!

    This small tutorial was based on "Rolling with Ruby on Rails" at onlamp.com: http://www.onlamp.com/pub/a/onlamp/2.../20/rails.html to get you started on JaguarPC hosting servers. The tutorial on onlamp is based on windows and WEBrick web server. You can ignore those and read on further on that tutorial and other tutorials:

    Rolling with Ruby on Rails (Part 1)

    Rolling with Ruby on Rails (Part 2)

    Ajax on Rails

    Also check out www.rubyonrails.com for more information.

    Masood N. | Chief Technical Officer
    JaguarPC.com


    Helpful Links
    Knowledge Base | Network Status

  2. #2
    Confused Newbie
    Join Date
    Jul 2003
    Posts
    12
    Using the ln -s technique, how would I run a rails app from the root of my domain. i.e. when they go to http://mydomain.com/ they get to see a typo powered blog?

    I have a feeling that simply doing ln -s on www would cause some problems for subdomains and what not.

    I guess there is always a redirect with a php script or .htaccess
    Last edited by kalel; 01-05-2006 at 11:08 PM.

  3. #3
    CTO JPC-Masood's Avatar
    Join Date
    Aug 2002
    Location
    Jaguar Servers
    Posts
    2,070
    You can remove public_html and create a link from it, but obviously you would only be running that particular application from it then (no subdomains etc.).

    If you want those, then you can have your application under public_html for better management. I usually do this for redirection:

    create index.php in public_html
    PHP Code:
    <?php
    Header
    ("Location: myapp/"); 
    ?>

    Masood N. | Chief Technical Officer
    JaguarPC.com


    Helpful Links
    Knowledge Base | Network Status

  4. #4
    JPC Member
    Join Date
    Aug 2002
    Posts
    6

    Question Instiki

    http://instiki.org/show/HomePage

    Any idea if it is possible to install Instiki here at JaguarPC? I'd like to use this Ruby based wiki, but when I go to install it I get the following...

    -jailshell-2.05b$ ruby instiki
    /home/mysite/public_html/buswiki/instiki-ar/vendor/rails/activesupport/lib/active_support/clean_logger.rb:13:in `remove_const': constant Logger::Format not defined (NameError)
    from /home/mysite/public_html/buswiki/instiki-ar/vendor/rails/activesupport/lib/active_support/clean_logger.rb:13
    from /home/mysite/public_html/buswiki/instiki-ar/vendor/rails/activesupport/lib/active_support.rb:31
    from ./script/../config/environment.rb:60
    from ./script/server:42
    from instiki:6

  5. #5
    CTO JPC-Masood's Avatar
    Join Date
    Aug 2002
    Location
    Jaguar Servers
    Posts
    2,070
    The error message is coming out of that software you are trying to install. Have you checked with the developer/vendor of instiki to find out about it?

    Masood N. | Chief Technical Officer
    JaguarPC.com


    Helpful Links
    Knowledge Base | Network Status

  6. #6
    A-Henh! Weevil's Avatar
    Join Date
    Apr 2003
    Posts
    46
    What's the best way to handle the development/production switch? From what I've seen using the environment variable is not the best way to handle it - Rails is pretty sharp, but it was clearly not designed for a shared server. Seems to me like the only choice on a shared server is to run in development mode since production mode won't reload anything without an apache restart (maybe you can force it from the console, I'm still learning). I fear it's going to require directory copying or something similarly course to keep devlopment and production separate.

  7. #7
    JPC Member
    Join Date
    May 2006
    Posts
    24
    hey masood, i am curious to know if you guys installed fast cgi support

    weevil : it is a very bad idea to let people access the website in development mode. it takes way too much ressources. it is very slow.

  8. #8
    A-Henh! Weevil's Avatar
    Join Date
    Apr 2003
    Posts
    46
    Wow, it's been a while since I posted that question, and admittedly I have not been able to give my Rails stuff much attention lately.

    Essentially you're saying that I should plan on copying files from a development area to the production area, but I think that this became moot recently when they disallowed using symlinks in the web folders anyway.

  9. #9
    CTO JPC-Masood's Avatar
    Join Date
    Aug 2002
    Location
    Jaguar Servers
    Posts
    2,070
    Quote Originally Posted by JoeWall
    hey masood, i am curious to know if you guys installed fast cgi support
    yes, fastcgi support is installed.

    Masood N. | Chief Technical Officer
    JaguarPC.com


    Helpful Links
    Knowledge Base | Network Status

  10. #10
    JPC Senior Member
    Join Date
    Jul 2004
    Posts
    70
    hmmm everyone harps on how fast and easy rails lets you deploy stuff - well from looking at that I will just keep using php thank you very much.

  11. #11
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Quote Originally Posted by lobos View Post
    hmmm everyone harps on how fast and easy rails lets you deploy stuff - well from looking at that I will just keep using php thank you very much.
    Rails lets you do certain things (like basic CRUD operations [create, retrieve, update, delete from databases]) very quickly. If you want to do more advanced things you still have to write code and using Rails means that you need to do it in Ruby, which probably means learning a new language.

    I know a lot of people are passionate about ROR, but I fail to find the same feelings. I've spent the past 10 or so years becoming a PHP expert and PHP continues to be better supported than ROR on most hosts, so I see no need to switch gears at this point.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  12. #12
    CTO JPC-Masood's Avatar
    Join Date
    Aug 2002
    Location
    Jaguar Servers
    Posts
    2,070

    Masood N. | Chief Technical Officer
    JaguarPC.com


    Helpful Links
    Knowledge Base | Network Status

  13. #13
    JPC Member
    Join Date
    Nov 2004
    Posts
    11
    Ok so I have putty running and I have logged in with SSH. I type "PWD" and "home/jthunder" shows up. now if I type "Rails Guestbook" I get "Ruby: Command not found" What is wrong? Sorry I am a Uber n00b to rails...

  14. #14
    JPC Member lamnk's Avatar
    Join Date
    Jul 2007
    Posts
    39
    That means you haven't installed ruby or rails to create project

  15. #15
    JPC Member
    Join Date
    Nov 2004
    Posts
    11
    Ok ROR was not installed. Now I type "Rails guestbook" and I get...

    "-jailshell-3.00$ rails guestbook

    Rails requires Ruby version 1.8.2 (2004-12-25) or later.
    You're running 1.8.1 (2003-12-25); please upgrade to continue.

    -jailshell-3.00$"

    How do I upgrade?

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •