Not following Rails table and field conventions

Whenever we generate a model then Rails expects that the underlying table has following:

1) table name starts with small letter and the word is in plural (ie, customers)

2) a table name that has more than one word in its name then it should be separated by an underscore (ie, line_items)

3) the field names with in the table should also start with small letters.

4) the primary key of the table should be an auto-incremented, integer type and with field name id

5) if you have a foreign key with in that table then it should be in the form table_name_id

If a table follows all the above conventions then the generated model will work straightaway. Otherwise follow these steps

  • If you are not following the conventions 1 & 2 and your table name is something like CustomerRecord instead of customer_records then you have to set the table name within your model just after the class name, like this:

class Customer < ActiveRecord::Base

set_table_name “CustomerRecord”

…..

end

  • If you are not following the convention 4 and your auto-incremented primary key is called Customer_ID instead of id, then do this

class Customer < ActiveRecord::Base

set_primary_key “Customer_ID”

….

end

  • If you are not following convention 5 and your foreign key is named as Customer_Category, then you have to specify that in your model relationship,

class Customer < ActiveRecord::Base

set_table_name “CustomerRecord”

set_primary_key “Customer_ID”

belongs_to :category, :foreign_key => ‘Customer_Category’

….

end

How to install Ruby on Rails with Sybase anywhere adapter on Windows


Installing Rails on Windows and using Sybase as db for the first time is a pain. So I thought to write a how to:

1) Download latest stable release of Ruby from http://rubyforge.org/frs/?group_id=167 on to your computer.

2) Run the executable and follow the onscreen instructions.

3) Once Ruby is installed successfully then go to command prompt and type ruby -v then hit enter. If everything was done properly then you will see the version of ruby, something like this

ruby 1.8.6 (date ...) [..]

4) Now you need to download the latest gem from http://rubyforge.org/frs/?group_id=126

5) Unzip it and then go to the command prompt again and type ruby setup.rb.

6) This will install the gem package manager. To be sure if everything went OK type gem -v on the command prompt to see the version of gem installed on your machine.

7) Now, to install rails run gem install rails --include-dependencies and wait while it is installed.

8) Once this process is complete then run rails -v and you should get the rails version as the output.

To communicate your rails app with Sybase you need to follow these steps.

1) Download sybaseanywhere_adapter.zip file (by Michael Scott)

2) Inside you have two ruby files and a read me file:

  • Put sybaseanywhere_adapter.rb file under your ruby installation, i.e., ruby\lib\ruby\gems\1.8\gems\activerecord-1.13.2\lib\active_record\connection_adapters
  • Put sybaseanywhere.rb file file under your ruby installation, i.e., ruby\lib\ruby\gems\1.8\gems\activerecord-1.13.2\lib\active_record\vendor
  • Now add sybaseanywhere in ruby\lib\ruby\gems\1.8\gems\activerecord-1.13.2\lib\active_record.rb file like this
    RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase frontbase sybaseanywhere )

3) Now create a directory called ADO, if you don’t already have it under your ruby installation directory, for example, ruby\lib\ruby\site_ruby\1.8\DBD

4) Download rub-dbi package from http://rubyforge.org/projects/ruby-dbi/ unzip it and put the ruby-dbi\lib\dbd\ADO.rb under your newly created directory ruby\lib\ruby\site_ruby\1.8\DBD\ADO

5) Your database.yml will also look a bit different like this

development:
adapter: sybaseanywhere
dsn: dsn_name
mode: DBI:ADO

Obviously, you have to create your dsn name using windows control panel. Now thats something off topic and I imagine you already know how to do this.

On windows you can use Aptana as your IDE (download from here) since it is free and has plugins for rails, svn, etc.

SP|hred.com launch

SP|hred.com is launched partially on 06/10/2007.

As I said in my earlier post that I will work on the idea but launching it within two days, yes … that’s quick.

I intend to not promote it for quite some time because I need to implement a few important things which forms the core of SP|hred. So if you stumble upon SP|hred.com in coming weeks then you are probably one of the first users of SP|hred.

Spread It or Shred It

SPhred.com is born while I was attending fowa and I am not sure yet whether its a good or bad idea but I am gonna work on it and try to keep it simple.

I created a rough architecture of the site during one of the presentation at future of web apps conference on fowa brochure (Sorry Ryan Carson…I just didnt carry enough paper with me).

I thought about the idea and then booked the domain last night itself, even started working on it.

Will talk later about what the site is actually about… 😉

FOWA

I am currently attending the Future of Web Apps Conference in London and really excited about the kind of technologies google, yahoo and other companies are bringing.

I would really love to experiment with fireagle and also signed up for their alpha release.

If I get some time then I would love to play with Adobe AIR as well.

Lots of interesting people with lots of ideas and yes some cool start ups as well.

I met with Paul Graham of YCombinator and talked with him about an idea I have for some time.

Update

Last few months were quite hectic as I moved from Plymouth to Reading to work with a great company on Agile Development and Ruby On Rails.

I am playing a key role in ajaxifying and  converting the existing desktop product to a web enabled product.

Live Help on mel-jol

A Live Help page has been added on mel-jol where users can chat and get help in real time as some people might require assistance in operating their forums on mel-jol or creating and modifying their business page or any other kind of assistance.
The live help page can be accessed by going to http://www.mel-jol.com/home/live_help.

But this page is accessible only if the user is logged in , i.e., mel-jol registered members who have activated their accounts.

If you have any queries which are not mentioned and clarified in the Forum >> Newcomer”s corner >> Help and Instructions forum or any other place on the website then do come to the Live Help session and ask your questions.

Live Help sessions are scheduled every night between 9pm – 11pm. Any schedule changes will be posted in Forum >> Newcomer”s corner >> Help and Instructions.

If this schedule is not convenient to any user then s/he can post it in Forum >> Newcomer”s corner >> Help and Instructions >> Live Help schedule and we will try to arrange some time convenient for both parties. However, we cannot guarantee that but we will try our best to reach a mutually convenient arrangement.

How to create a Business Page on mel-jol.com?

If you are already registered on mel-jol, then:

1. Login.
2. Click on the Business Pages link available from the Main Menu.
3. You will find a link on this page to create your Business Page, click on that (only visible, if you are logged in).
4. On the next page, you will see a form to fill information about your business.
5. Choose a category for your business from the “Select Category” options.
6. If no suitable category present for your business then create one by clicking on No suitable category for your business? Click here link. A box will appear, simply fill in your business category name and click on the Create Category button.
7. Now select the category you just created from “Select Category” options.
8. Enter your business name in the “Business Name” box (within 90 characters).
9. Enter a short description of your business in the “Short Description” box (within 180 characters).
10. If you have your own website then enter the full address (including http://) in the website address box.
11. Now put all the information you want in the “Detail Description” box.
12. If you want to put an offer/service/product information then use Would you also like to add what you offer (service or product)? Click here link to enter the details.
13. Click on “Add Business” button and you are done.
14. If you want to add more products/services then go to your business page, which will have the address http://www.mel-jol.com/biz/YourUsername and click on Want to add additional services or products? Click here link. This link is available after your business information and before the product/service description start (if any present).
15. Once you click on this link, you will see a box with a form to add the relevant information.
16. After filling in the information, click on “Add Offer” button and you will immediately see a message “Added successfully”.
17. Scroll down the page, to see the product / service you just added.
18. To edit your business information or products / services, use the Edit link given in each section or simply click on the text, which will change the text into a box where you can edit information, once done click “OK” or “Cancel” to undo the changes.
19. To see, how your business page will appear to others logout and refresh/reload your business page.

NOTE: You can do all these tasks only if you are logged in otherwise you won”t see the Edit/Delete links.

If you face any problems then go to the Forum >> Newcomer”s corner >> Help and Instructions >> How to create a Business Page? and post a reply using Post Reply link and you will get a reply asap.

Application Error

I just thought to let all the users know that if you get

Application Error

Rails application failed to start properly

then simply refresh / reload that page. Hopefully, it will work fine once you refresh that page or press Ctrl + R key together.

However, if the problem persists, then please contact support@mel-jol.com