Skip to main content

Posts

Steps for exception notifier Ruby -1.9.2 and Rails 2.3.8 For Exception Notifier in rails

Steps for exception notifier 1)ruby script/generate mailer notifier 2) ruby script/plugin install git://github.com/rails/exception_notification.git -r "2-3-stable" 3)lib/notifier.rb to change the ->  @@sender_address = %("Exception Notifier" <xxx@gmail.com>) -> For yahoo only we need to change these line 4)Add these line to  config/environments/development.rb and config/environments/production.rb config.action_mailer.default_url_options = { :host => 'local host:3000' } config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true #for gmail  ActionMailer::Base.smtp_settings = {    :address              => "smtp.gmail.com",    :port                 => "587",    :domain             ...

Implementing Roo gem in Rails 3

Roo gem allows us to access the contents of Open-office spreadsheets (.ods) Excel spreadsheets (.xls) Google (online) spreadsheets Excel’s new file format .xlsx Following is a basic example to demonstrate how to read the datas from an excel sheet and save to your database.Suppose you have an excel sheet named student_details.xls which contain the student details such as “Name”,”Phone”,”Address”.We have to save them in our database but it will take a huge time if we insert them manually.Here we can user “ roo ” gem to fetch the datas from excel sheet and save to database in a fly. Step – 1 Add the gem in your gem file gem ‘roo’ Then run the ‘ bundle install ‘ Step – 2 Place your excel sheet in the rails application such as in public folder. Step – 3 Now its time to change your controller like below. Add the following line in your controller require ‘roo’ Create a new method where you will fetch the data from excel sheet and save it in your database....

Ruby roo gem uploading excels

Right so I've checked out Roo. Great gem and all and have a really basic application that doesn't have no models. And basic controller, class and view and I can't seem to get a spreadsheet to upload as I am getting OLE2 signature is invalid error. I have the following basic setup Controller class SpreadsheetServiceController < ApplicationController def new end def create parser = SpreadsheetTagService.new(params[:spreadsheet][:file]) respond_to do |format| format.all {render :json => 'Done'} end end end SpreadsheetTagService class SpreadsheetTagService include Roo def initialize(uploaded_file) @tmp_destination = "#{Rails.root}/tmp/tag-import.xls" @file_path = save_file_to_tmp(uploaded_file) @file = File.new(@file_path) read_file(@file) end private def save_file_to_tmp(uploaded_file) FileUtils.mv(uploaded_file.tempfile.path, @tmp_destination ) @tmp_destination ...

Rails Date Formats

Rails Date Formats % a - The abbreviated weekday name ( '' Sun '' ) % A - The full weekday name ( '' Sunday '' ) % b - The abbreviated month name ( '' Jan '' ) % B - The full month name ( '' January '' ) % c - The preferred local date and time representation % d - Day of the month ( 01 .. 31 ) % H - Hour of the day , 24 - hour clock ( 00 .. 23 ) % I - Hour of the day , 12 - hour clock ( 01 .. 12 ) % j - Day of the year ( 001 .. 366 ) % m - Month of the year ( 01 .. 12 ) % M - Minute of the hour ( 00 .. 59 ) % p - Meridian indicator ( '' AM '' or '' PM '' ) % S - Second of the minute ( 00 .. 60 ) % U - Week number of the current year , starting with the first Sunday as the first day of the first week ( 00 .. 53 ) % W - Week number of the...

Rails generate Csv or xls files

def get_all_users     csv = ""     csv1="Id,Email"     csv2 = ""     csv << "#{csv1}\n"     csv << "#{csv2}"     @user = User.find(:all)     @user.each do |x|        csv2 << "#{x.id}"        csv2 << ",\"#{x.email}\""        csv2 << "\n"      end    csv << csv2    send_data csv, :type => 'text/xls; charset=utf-8; header=present', :disposition => "attachment;filename=xyz.xls" (or) send_data csv, :type => 'text/csv; charset=utf-8; header=present', :disposition => "attachment;filename=xyz.csv" end In Views <p><%=link_to "hello",:controller => "user" ,:action => "get_all_users"%></p>

MYSQL DATAT TYPES EXPLANATION?

MYSQL DATAT TYPES EXPLANATION? What is data type 1. A data type specifies a particular type of data, such as integer, floating-point, Boolean etc. 2. A data type also specifies the possible values for that type, the operations that can be performed on that type and the way the values of that type are stored. MySQL data types MySQL supports a number of SQL standard data types in various categories. MySQL has Numeric Types, the DATETIME, DATE, and TIMESTAMP Types and String Types. Data types are discussed on this page are based on MySQL community server 5.6 MySQL Numeric Types MySQL supports all standard SQL numeric data types which include INTEGER, SMALLINT, DECIMAL, and NUMERIC. It also supports the approximate numeric data types (FLOAT, REAL, and DOUBLE PRECISION). The keyword INT is a synonym for INTEGER, and the keywords DEC and FIXED are synonyms for DECIMAL. DOUBLE is a synonym for DOUBLE PRECISION (a nonstandard extension). REAL is a synonym for DOUBLE PRECISION (a nonstandar...

Paperclip uploading files (or)images to amazon s3 for Ruby on rails?

Paperclip uploading files (or)images to amazon s3 for Ruby on rails ? 1)Add a gem 'gem 'aws-sdk' 2)bundle install 3)app/models/profile.rb-----Model add this code has_attached_file :image,                    :storage => :s3,                    :bucket => "yyyyyy",                    :s3_permissions => "public-read",                    :path => "profiles/:id/:basename.:extension",                    :s3_credentials => {                 ...