Showing posts with label GitHub. Show all posts
Showing posts with label GitHub. Show all posts

29 January 2010

Generating Calendar With Rails

Download the source code from GitHub

Working on a Rails CMS based project using BrowserCMS, there was a requirement to have a page which would display a calendar for the current month and onClick of each date, it has to make an Ajax request to query the database table and update a portion on the same page.

Everything is fine with the requirement, but a Rails calendar with each date sending an Ajax request to the controller?

My initial move was to look for some Rails plugin which would serve this purpose. Had a thorough Google search on this. Time was ticking, I managed to find one or two Rails calendar Plugin, but when tried on my project, it did not serve the exact purpose of each date sending the Ajax request. No much help was there on this in any Rails based forum as well.

This finally made me to think of writing the code for generating the calendar of my own. It was indeed going to be a tough task. But I had no other choice left in-front of me.

I have shared the code for the same through my GitHub account.

There in the GitHub repository you will find only a controllers folder and a views folder. Well that's all we need to get this done. If you have a Rails project up and running, you can go ahead and generate this Calendar Controller and use the code and modify it, style it as per your own requirement.

Here what I have done is, in the "calendar index" page you can see the calendar for the current month, with links for next and previous months, so that you can have a view of all the months. When you click on the next/previous links, the months partial is being updated. Similarly, onClick of each date will update a test "div" with the value of month and date. You can apply any logic here and make it work for your purpose.


Ruby/Rails Tips for the day:

=>How to get the starting day of the month ?

Loading development environment (Rails 2.3.5)
>> date = Date.today
=> Fri, 29 Jan 2010
>> start_date = Date.parse "#{date.year}-#{date.month}-01"
=> Fri, 01 Jan 2010

=>How to get the last day of the month ?

>> last_date = (start_date >> 1)-1
=> Sun, 31 Jan 2010

=>How to get the weekday of a particular date?

>> start_date.wday
=> 5

Special thanks to Nithin Bekal who helped me in getting this work done in no time.
If anyone uses this code for their application, please share with me the improvements made.

25 January 2010

Share Source Code Using GitHub- It's Social Coding!

Done writing the codes of your current project? And is excited about it and want the whole developer community to know about your latest project? Then Lets Git It!

Yes, I am also equally excited about my latest project and I wanted it to share with the developer community through GitHub-Social Coding!

The application was developed using Ruby On Rails and hence the hosting provider is HostingRails. So I have my application running up there. So all I had to do was commit the source code from HostingRails into the GitHub repository.

I will be explaining the exact procedure that I followed to commit the source code of my application into GitHub repository directly from HostingRails.
I use PuTTy which is an open source telnet and SSH Client for the Windows and Unix platforms.

Since my application was hosted in HostingRails, I logged into it via PuTTy and I was taken into my root folder. If you are not aware of PuTTy interface, then I would say it is just a Unix Terminal for you to work on. So from the root folder I had to get in my project folder which I did using CD command.

Well before we do anything , a GitHub account is necessary or else where are we going to commit all our source code! So I did create a GitHub Account and I am all set for Social Coding.

Next I had to create a New repository.(See Images)








Once I provided all the information for creating the repository, I hit create-repository. And that's all. After I created the repository, I was redirected to the new repository page which had the basic information on how to commit the source codes.

here's what i did for committing the source code for my application.

In PuTTy, as i was already in my application folder:

email@email.com [~/rails/My_Project]#

Next i had to initialize the git in my application:


email@email.com [~/rails/My_Project]#git init
Initialized empty Git repository in /home/fedenac/rails/testing/.git/

Once initialized, I had to include all the folders and files.

email@email.com [~/rails/My_Project]#git add .

And after that commit it


email@email.com [~/rails/My_Project]#git commit -m 'any message here'

Then I had to add the remote origin


email@email.com [~/rails/My_Project]#git remote add origin git@github.com:techslam/test.git

In the above command "git@github.com:techslam/test.git" is the URl which we find at the top of the page after successfully creating the repository.(See Image)



And finnaly we push it:


email@email.com [~/rails/My_Project]#git push origin master

And that's it. When I checked my repository all my source code was ready to be shared with the wonderful development community out there.

So Folks, what's your say on GitHub feature. I am really enjoying it and is going to explore it deeper and deeper.