Ajax it is :)

Today I learned to add a ajax call to the application. It was very easy and straight forward. Ruby has a easy way of doing it. Passing the parameter :remote => true, will make the call ajax/js! To handle thi, the function we call, need to add format.js instead of format.html. Then I created a file jsfile.js.rjs.

That’s it for now. With long working hours, squeeze in my exercise schedule in between, that’s all I could do today. Lot to finish ahead! Hope I can finish the book in two weeks!

Model Relations & Migrations etc!

Today, I was not able to concentrate much. It happens sometimes, my brain just stop working, easy and simple things look so complex and impossible to understand. Anyway, I tried to at least do some. Here are some more things I learned today and I should notice them:

– Learned about using session. Rails has access to session, so I can easily define any session value for keep record related to the user of that session, [ex: session[:value]=val]
– Relation among tables in model class. belongs_to, has_many. If I use a belong_to b, I can access a.b.id. Amazing, isn’t it?
– button can be used for POST method where link calls GET method. In the CRUD functions, “create” is the POST one!!
– Rails has a way of telling what to do during migration if the following pattern is used:
add_XXX_to_TABLE, remove_XXX_to_TABLE,

First Few Things!

I just built a basic application following the book “Agile Web Development with Rails”. Things to notice so far:

– added mock data to the file db/seed.rb and ran rake db:seed to populate db with those mock data.
– cycle helper is used in a row (<tr class=”<%=cycle(‘list_line_even’, ‘list_line_odd)%>”>) to make sure rows have alternate background color.
– strip_tags is used to remove html tags from the string.
– javascript_include_tags and stylesheet_link_tag is used in application.html.erb to add all the stylesheet and js scripts from punlic folder.
– link_to method for delete took a confirm message as parameter (<%= link_to ‘Destroy’, testable, :confirm => ‘Are you sure?’, :method => :delete %>)
– added following validation to the testable model
validates_presence_of :abc, :efg, :hij
validates_numericality_of :abc, :message => “Must be a this.”
validates_uniqueness_of :efg
validates_format_of :efg, { :with => “”}i, :message => ‘must be a this/that’}
– used map.root :controller=> ‘test’ to route main page to test page.
– used number_to_currency helper to show price with $ sign.

**I updated gem and rails the following way in my Snow Leopard OS:
-sudo gem update –system
-sudo gem update rails

MacBook Pro and Starting My Rails Journey!

After hesitating for months/years, I realized its time I decide 🙂 Everybody around me are using Mac for development and I need to sharpen my skills too in something which will add more value! So I bought a MacBook Pro yesterday 🙂 I didn’t have to go through the ordeal of installing all the stufs for rails/sqlite etc. It seems, this MAC OS 10.6(Snow Leopard) comes with all if this! So all I needed to do is install RubyMine and git and I was all set up to start working!

Today, I am going to start my next project, something more meaningful and helpful for learning real rails development. FYI, I am following the book: Agile Web Development with Rails by Sam Ruby, Dave Thomas and David Hansson. Wonderful book to learn rails.

I am planning to build a shopping cart application, where I will have a Product side and a Store side to control the main app as per the book. Let me began my journey to rails application then!

Happy Programming!!

Ruby on Rails Installation & My First Rails Project!

Installation Steps:

1. Went to http://rubyinstaller.org/ to get RubyInstaller to install latest version of Ruby on my machine.
2. After installing went to command prompt, typed: ruby -v to see if it is installed.
3. Got an error as path needs to be set, so set the path in my environment setting.
4. I also checked the gem version by: gem -v. (RubyInstaller include RubyGem)
5. To have sqlite, went to http://www.sqlite.org/download.html, got sqlite-3_7_3.zip & sqlitedll-3_7_3.zip. After unzipping, copied the three files (sqlite3.exe, sqlite3.dll, sqlite3.def) to my C;/Ruby/bin/ folder.
6. Now I need to install sqlite & rails: I ran: “gem install sqlite3-ruby” for sqlite and “gem install rails”.
7. Then I installed RubyMine(http://www.jetbrains.com/ruby/) to use as my editor.

Creating a demo application:

1. Once I was done installing, I did the following in command prompt:
c:\rails_projects>rails new demo
This will create a project for me.
2. Then go inside the project to start the server and see the result!
c:>rails_project\demo\rails server (PLEASE NOTE: with rails 3, you cant use ruby script/server anymore, you have to use rails server to start the server)
3. The server will start by default in port 3000. Too see your demo: go to http://localhost:3000/

Getting git for version control:

1. I need to get git to make sure everything is version controlled. So I got the window version from http://git-scm.com/

2. Once I had the Git bash,  I went inside my application, ran the following command in c/rails_project/demo

$ git init
$ git add .
$ git commit “My first project”
$ git status

The last command is to see status of my project.

Hurrayyyy! My first demo project is running!!!!