Posts Tagged ruby on rails

Timestamps arent necessary

Whenever we create models in rails, we get a migration where timestamps are added to it. I accepted it as a rle of thumb till a day I was required to wrap my classes around a database in which the tab;es dd not have time stamp fields created_at and updated_at

Well then I tried the following piece of code rails g model tweet content:text and modified its migration so that it looks as floows

Look at it, it has no timestamps in it. I ran the migration and tried this code on the rails console

And it worked, proving Timestamps aren’t necessary. But its better to have them


, ,

1 Comment

Very Simple Search for Active Records

Okay, you might encounter a need to put very simple search for active record / model in your Rails app and here is it. Put this code in your active record model:

Note this line

columns = [:name, :address, :city, :pin, :ph]

in the code snippet, give your own column names in that array.  This array can contain columns that are string and text type. Lets say you have put these stuff in a class called Person , to search it you need to issue a command like this "Karthik chennai"

This stuff works well with Sqlite, Postgre and MySQL. If you have tried this out with other DB, please add it in comments. Bye.

, , ,

Leave a comment

Ditching my Rails Book

Hello People,

Am ditching my Rails book. well, I am in  a full time job now, in a kinda hot situation (not that girls here makes me hot),  but some things makes my blood boil, like peoples insisting on using Windows and Ditching Linux. WHATTTTTTTTTTTT? Ya they say this and that for that. Plus there is ample things here to work on. So till my friends here become a programming Jedi, I wont be free.

So I am ditching my Rails book which I announced here, and am going to Improve my Ruby book which can be downloaded clicking here.

, , , ,

Leave a comment

Planning for a Rails book

ror cover girl

Well, after the success of I Love Ruby( ), I am planning fora Rails book. You can see its cover above 😉

This book will be released under GNU free documentation license. Time will tell if this book will become a success.

, , , ,

1 Comment

Auto Routing In Rails 3

Long long ago,  one fine day I switched from Rails 2.x to Rails 3.x and I notices a thing like this, when you have a controller like this one

class UserController < ApplicationController

  def profile
    @title = "Your Links"
    @links = Kaminari.paginate_array(current_user.links | current_user.jeweled_links).page(params[:page]).per(20)

  def search
    @title = "Search for #{params[:s]}"
    @links = current_user.search_links(params[:s]).page(params[:page]).per(20)
    render :profile

and if you type http://localhost:3000/user/profile , you will get an error unless the route get ‘user/profile’ is added into routes.rb .
It might be frustrating for one to add hundreds of routes in a large project and quiet not so good looking to see a huge routes.rb file, so how to go about the Rails 2 way where you put an action in an controller you can simply access it?
Well its quiet simple, just launch your routes.rb file and find this line
match ':controller(/:action(/:id))(.:format)'

It would be commented out, so uncomment it. Now launch http://localhost:3000/user/profile in your browser and it will load!

, ,


Launching Ruby Links

Possible Ruby Links Logo

Possible Ruby Links Logo

Hello people. One problem with Ruby and its spinoffs like Rails, Sinatra and blah blah is that its documentation, books, tutorials are scattered all over the internet. I was wondering could this all be got under one place. In fact Google has done it. But is googlean excellent vertical specific search engine and book marking thing? No. Well I present you with .

This is not a search engine though, all you can do is, if you find a great link about Ruby and its allied technology, you can post it here. If soe one likes it, they can jewel it. You are presented with your own page here all the links posted and jeweled by you are listed, so that there is no need for you to scratch your head and say, “where did I see that?”

Ruby Links is a free software, hosted here , please post bugs and suggestions there, ad if possible contribute for the benefit of Ruby community.

, , ,

Leave a comment

Learning Postgre is Quiet Essential

When its in PHP, people always proffered LAMP, that is PHP running on Apache server,  data stored in MySQL and all this runs on Linux server. Now Rails is slowly bt surely chipping into PHP’s territory. ore people like to start their project with Rails than with PHP (at least the people I know). Or should  I say Sinatra as its very easy to learn.

Now there is a change here. MySQL was popular with Rails, but its no more now. Not because its technically inferior to Postgre, but because its owned by Oracle. Oracle is a big company. Its just interested in making profit unlike the free software community which is interested  in delivering software to people so that they can benefit out of it. This corporate interest has made MySQL stall. The initial creator of MySQL, Monty Widenus has even started another project called MariaDB, a drop in replacement to MySQL.

But the mood in Rails community is clear. Most Rails apps as far as I know run with PostgreSQL. So learn Postgre. If your app receives lot of hits, possibly tou might dig deep into raw sql to improve its performance. Postgre also has a thing called Geographic Information System in which you can store geographic data, and ask queries like ‘which is the bakery thats nearest to my home?’ and so on.

So if you are interested really and are sure that your app will be popular, use and dig into PostgreSQL.

, , , , ,

Leave a comment

%d bloggers like this: