Archive | Ruby On Rails RSS feed for this section

Blog Shifted

13 Sep

Dear Friends,

I got lot of support from you and I am very happy to let you know that Finally I have migrated from WordPress Hosting to own hosted Blog.

Yes, I believe WordPress is the best blogging platform available in market. So I have used wordpress again for my blog.

Here is a link for my New Blog :- http://mukundtechie.com

I request all my followers to visit my site and suggest me, What can be done to make it more interactive and pleasing to see posts.

All your feedback and suggestions are welcomed.

Thanks,

Mukund Chaudhary

New Blog : http://mukundtechie.com

 

Event Calender in Ruby on Rails

18 Jun

Hi Friends,

In the busy scenario every one want to manage his events. so almost every site need to connect their app to Event management.

So we will discuss how to connect your API to Google Account Using ROR.

Google Calender API in Ruby on Rails 🙂

  • Google Calender: a pretty simple and full featured google calendar library in ruby, with optional Rails plugin. A good option for anyone who’s interested in accessing or exporting Google Calendars into HTML or Excel. Though the Event support is excellent, my application needed finer grained control over multiple calendars under each user, and this library didn’t include the functions to determine calendars programmatically.
  • GCalAPI: also a good and simple API for Google Calendar, though it provided a better interface for finding calendars associated with a user account. Unfortunately, the documentation is a little lacking, and there was no built in way to create a new calendar. But, I ended up using this library despite the drawbacks.

GCal4Ruby is a Ruby Gem that can be used to interact with the current version of the Google Calendar API. GCal4Ruby provides the following features:

  • Create and edit calendar events
  • Add and invite users to events
  • Set reminders
  • Make recurring events

Installation
To install GCal4Ruby, run the following command:

>gem install gcal4ruby

Documentation
Sourcecode and documentation for the GCal4Ruby gem is available at http://cookingandcoding.com/docs/gcal4ruby/.

Hope you can make it easy.

For any query feel free to comment.

Rails Upload

25 May

Today only very few applications are there which does not require any kinds file uploading.

So I came up with easy file uploading in Ruby on Rails.
let’s start off with a new Rails application called upload. So let’s create basic structure of the application by using simple rails command.

C:\ruby> rails upload

Now do this
C:\ruby> cd upload
C:\ruby> mkdir upload\public\data

Now creating  controller and models,

Creating Model:

C:\ruby> ruby script/generate model DataFile
     exists  app/models/
     exists  test/unit/
     exists  test/fixtures/
     create  app/models/data_file.rb
     create  test/unit/data_file_test.rb
     create  test/fixtures/data_files.yml
     create  db/migrate


create a method called save in data_file.rb model file.

class DataFile < ActiveRecord::Base
 def self.save(upload)
   name =  upload['datafile'].original_filename
   directory = "public/data"
   # create the file path
   path = File.join(directory, name)
   # write the file
   File.open(path, "wb") { |f| f.write(upload['datafile'].read) }
 end
end


Creating Controller:

C:\ruby> ruby script/generate controller Upload
     exists  app/controllers/
     exists  app/helpers/
     create  app/views/upload
     exists  test/functional/
     create  app/controllers/upload_controller.rb
     create  test/functional/upload_controller_test.rb




Now we will create two controller functions first function index will call a view file to take user input and second function uploadFile takes file information from the user and passes it to the ‘DataFile’ model. We set the upload directory to the ‘uploads’ directory we created earlier “directory = ‘data'”.

class UploadController < ApplicationController
 def index
    render :file => 'app\views\upload\uploadfile.rhtml'
 end
 def uploadFile
   post = DataFile.save(params[:upload])
   render :text => "File has been uploaded successfully"
 end
end

Here we are calling function defined in model file. The render function is being used to redirect to view file as well as to display a message.

Creating View:

Finally we will create a view file uploadfile.rhtml which we have mentioned in controller. Populate this file with the following code:

File Upload

 'uploadFile'},
                       :multipart => true) %>

Select File :



Here everything is same what we have explained in earlier chapters. Only new tag is file_field which will create a button to select a file from user’s computer.

By setting the multipart parameter to true, you ensure that your action properly passes along the binary data from the file.

     create  app/helpers/upload_helper.rb
This method will be called by the application controller.
     create  db/migrate/001_create_data_files.rb


Script is ready to serve just run Ruby script/server

and then go to http://localhost:3000/upload/index



Thanks hope every thing works fine. If any problem I will be there to help you.

Ruby on Rails

11 May

Hello friends,
Rails is a famous MVC frame work. Various application that are famous these days were made in ruby on rails.
Twitter is one of which…

Love to learn ruby on rails follows http://www.rubyonrails.org for more information.