Thursday, November 24, 2011

How to export CSV in rails 3

class BooksController < ApplicationController
 
  # GET /books
  # GET /books.xml
  def index
   step=2
    @books = Book.paginate(:all, :page=>params[:page], :per_page=>2)
   str = ""
    datestamp = Date.today.strftime("%d%b%Y%H")
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @books }
      format.csv do
     
        csv_data=FasterCSV.generate(str) do |csv|
          csv << ["Serial", "Name","Author Name" ,"Description", "pages","isbn", "Created At", "Modified At"]
         
         
         
           @books.each do |b|
          csv << [b.id,b.name,b.author.name,b.description,b.pages,b.isbn,b.created_at,b.updated_at]
     
        end
         end
        send_data csv_data,
    :type => 'text/csv; charset=iso-8859-1; header=present',
    :disposition => "attachment; filename=books"+datestamp+".csv"
        flash[:notice] = "Export complete!"
      end
    end
  end
 
 
  # GET /books/1
  # GET /books/1.xml
  def show
    @book = Book.find(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @book }
    end
  end
 
  # GET /books/new
  # GET /books/new.xml
  def new
    @book = Book.new
   
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @book }
    end
  end
 
  # GET /books/1/edit
  def edit
    @book = Book.find(params[:id])
  end
 
  # POST /books
  # POST /books.xml
  def create
    @book = Book.new(params[:book])
   
    respond_to do |format|
      if @book.save
        flash[:notice] = 'Book was successfully created.'
        format.html { redirect_to(@book) }
        format.xml  { render :xml => @book, :status => :created, :location => @book }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @book.errors, :status => :unprocessable_entity }
      end
    end
  end
 
  # PUT /books/1
  # PUT /books/1.xml
  def update
    @book = Book.find(params[:id])
   
    respond_to do |format|
      if @book.update_attributes(params[:book])
        flash[:notice] = 'Book was successfully updated.'
        format.html { redirect_to(@book) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @book.errors, :status => :unprocessable_entity }
      end
    end
  end
 
  # DELETE /books/1
  # DELETE /books/1.xml
  def destroy
    @book = Book.find(params[:id])
    @book.destroy
   
    respond_to do |format|
      format.html { redirect_to(books_url) }
      format.xml  { head :ok }
    end
  end
end

Sunday, May 15, 2011

Preparing your applications for a Windows 7 migration

Windows 7: The Missing ManualDesktop applications that worked flawlessly in Windows XP -- and even Windows Vista -- may not be so perfect in Windows 7. If you're planning a Windows 7 migration, there are several things you should do to minimize app-related problems.
Take a desktop application inventory
The first step is to take an inventory of your organization's applications. Depending on the size of your enterprise, you can either perform the inventory manually, or you can use an automated inventory collection program.
The Microsoft Application Compatibility Toolkit is a good and free  option if you're going the automated route. The tool is designed to take an inventory of desktop applications and provide information on each app's compatibility with Windows 7. In addition, the Windows 7 Upgrade Advisor can be a useful product in smaller organizations.

Wednesday, March 16, 2011

Benefits of having a wireless Network

Medialink - Wireless N Router - 802.11n - 150 Mbps - 2.4 Ghz - NEW Design w/ Internal AntennaWorking wirelessly can offer you the following benefits.
  • Flexibility: The lack of cables that comes with wireless networking enables you to roam with your mobile PC. You can roam from your office to a nearby conference room for a meeting, or from the couch in the living room to a kitchen for a snack. For example, if you're working wirelessly in a meeting you can printout a report for a co-worker without having to leave the meeting.
  • Time-saving: If you're waiting for an important response you can use your mobile PC to monitor your email even when you're in meetings or at lunch. As soon as you get the data needed, you can promptly forward it to your customer rather than wondering whether the information has come in while you were away and having to run back to your office between meetings and other commitments.
  • Increased productivity: Working wirelessly enables you to turn down times between meetings or while in transit into productive time. For example, you may be attending a conference and just found out that one of the sessions you were planning on attending has been cancelled. Rather than waste the next hour, you can check email, start compiling your trip report, or order your son's birthday present.
  • Easier collaboration: Using wireless mobile PCs, you can easily share files and information with others. For example, you can collaborate on a presentation with colleagues during a flight delay in an airport lounge, or you can share the syllabus of a course while attendees so that they can take more digitally during the class.

    Saturday, February 5, 2011

    How do you get started using wireless?

    Connectland 2.4 GHz Wireless Keyboard (Multimedia Hot Keys) and Optical Mouse Combo, Black ColorYesterday i looked i was able to differentiate between between different terms of wireless computing.  Now i would like to peep in the way you start to get wireless.
    The only thing you really need to go wireless (in addition to a mobile PC) is a wireless PC Card. Depending on the age of your mobile PC, the card is either built-in or needs to be inserted in the PC Card slot and includes an antenna. In addition, you can also use wireless keyboards and mice, which can provide more freedom and flexibility when you're working in your office.
    It's always good to research the available hot spots in the area you're planning on visiting (whether a neighborhood in your city you're not familiar with or a city on the other coast).
    As you head out in this brave new world of wirelessly connectivity, you can connect to a wireless network (whether at home, at work, or on the go).
    Lets go wireless reader. 
     

    Friday, February 4, 2011

    What you need to know about wireless Networks

    Cisco-Linksys WRT54G2 Wireless-G Broadband RouterMany companies are making the leap to wireless networks in the office for both financial savings in overall equipment and sheer convenience for their employees. They also often provide mobile PCs with wireless capabilities to their employees so that they can be productive anytime anywhere, hence enhancing the company's bottom-line.
    In this article, I will explain what WiFi is and how it works. I will also discuss what you need to start working wirelessly as well as what you can expect to gain from doing so. Finally, I'll discuss the precautions you should take when working on the go.

    What is WiFi? Learn the lingo

    Wireless, or WiFi, technology is another way of connecting your computer to the network using radio frequency and no network cables.
    Wireless works similarly to cordless phones; they transmit data from one point to another through radio signals. But wireless technology also requires that you be within the wireless network range area to be able to connect your computer. There are three different types of wireless networks:
    • Wireless Local Area Network (WLAN): WLAN are wireless networks that use radio waves. The backbone network usually uses cables, with one or more wireless access points connecting the wireless users to the wired network. The range of a WLAN can be anywhere from a single room to an entire campus.
    • Wireless Personal Area Network (WPAN): WPANs are short-range networks that use Bluetooth technology. They are commonly used to interconnect compatible devices near a central location, such as a desk. A WPAN has a typical range of about 30 feet.
    • Wireless Wide Area Networks (WWAN): WWANs are created through the use of mobile phone signals typically provided and maintained by specific mobile phone (cellular) service providers. WWANs can provide a way to stay connected even when away from other forms of network access. Also, be aware that additional charges are often associated with the usage of WWANs in some locations.

    Tuesday, January 25, 2011

    Lazyscope makes your twitting easier and fun.

    This video shows how lazy twitters like me can read every bit of information on their tweets..Click here for more