A Simple example of Using iframe in Rails

Write the code for iframe and in the src option give the path that defined in routes. It will render the file which corresponding action of the controller renders.

An Haml example is given below:

%iframe{:align => "center", :name => "window", :src => "#{list_make_shipments_path(:ids => "#{@shipment_success_responses.collect(&:id).join(",")}")}", :height => "1000px;", :width => "1100px;", :style => "float:left;margin-top:30px;"}

Create an Image from base64 encrypted image digest data

Suppose you have a base64 digest data of an image, how are you going to display it in your website?

For example You an encrypted image data like this : PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9JRVRGLy9EVEQgSFR…

Here is an example in haml, how to display the image from this data ( you can make corresponding HTML from this if you are using a Html file)


%img{:alt => "File Icon", :src => "data:image/gif;base64,PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9JRVRGLy9EVEQgSFR...", :style => "float: left;margin-top:200px;", :id => "my_image_id", :class =>"blahblahblah"}

 

Importing contacts from your email using Rails ‘contacts’ gem

Using ‘contacts’ gem you can import all your contact emails.

Step 1:

In Your Gemfile add,

## For Importing Email Contacts
gem "contacts", :git => "git://github.com/abhilashak/contacts.git"
gem "gdata", :git => "git://github.com/abhilashak/gdata-1.git"

For importing from gmail, we need the gem ‘gdata’.

Do bundle install

you are done.

Step 2:

In your views/import_profile_contact/new.html.erb file,

<%=  text_field_tag "profile_contact[email]", "" %>

<%=  password_field_tag "profile_contact[password]", "" %>

Put one more hidden field tag to know that from which email the user need to import

<%= hidden_field_tag :contact_from, @contact_from %>

the values of @contact_from may be gmail, yahoo mail, hot mail. According to which option user clicks pass the corresponding string.

Step 3:

In your controller get the email and password params

@contact_from = params[:contact_from]

email = params[:profile_contact][:email]
password = params[:profile_contact][:password]

if @contact_from && email && password
  if @contact_from == "gmail"
    @imported_contacts = Contacts.new(:gmail, email, password).contacts
  elsif @contact_from == "yahoo_mail"
    @imported_contacts = Contacts.new(:yahoo, email, password).contacts
  elsif @contact_from == "hotmail"
    @imported_contacts = Contacts.new(:hotmail, email, password).contacts
  end
end

You will get all contacts in an array….

Install Rails 3.1.3 and set up in Linux

Install RVM

If you are not already installed RVM install from here:
https://rvm.beginrescueend.com/rvm/install/

If you already have rvm installed, update it to the latest version.

$ rvm get latest
$ rvm reload
$ rvm -v

Create a Rails 3.1.3 Gemset

Create a default Rails 3.1.3 gemset. It’s advisable to create a new gemset for each application you build. But to get started, create just one new Rails 3.1.3 gemset as your default.

$ rvm ruby-1.9.2-p290@rails313 --create --default

To see a list of the gemsets you have installed:

$ rvm gemset list

And see a list of the gems included with the standard Ruby installation:

$ gem list

$ rvm list gemsets

rvm gemsets

ruby-1.9.2-p290 [ i386 ]
ruby-1.9.2-p290@global [ i386 ]
=> ruby-1.9.2-p290@rails313 [ i386 ]

Make sure you are using the newest version of Rake before you install Rails 3.1.3.

$ gem update rake
$ rake --version

Install Rails

$ gem install rails -v "3.1.3"

DETAILS:

RVM Version

rvm 1.10.1 by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.beginrescueend.com/]

Bundler Version

builder (3.0.0)
bundler (1.0.21)

LOCAL GEMS after installed Rails 3.1.3

*** LOCAL GEMS ***

actionmailer (3.1.3)
actionpack (3.1.3)
activemodel (3.1.3)
activerecord (3.1.3)
activeresource (3.1.3)
activesupport (3.1.3)
arel (2.2.1)
builder (3.0.0)
bundler (1.0.21)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.0)
json (1.6.5)
mail (2.3.0)
mime-types (1.17.2)
multi_json (1.0.4)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.1)
rack-mount (0.8.3)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.1.3)
railties (3.1.3)
rake (0.9.2.2)
rdoc (3.12)
sprockets (2.0.3)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.31)

Unicorn Version

unicorn (4.1.1)
All Gems installed
actionmailer (3.1.3)
actionpack (3.1.3)
activemodel (3.1.3)
activerecord (3.1.3)
activeresource (3.1.3)
activesupport (3.1.3)
addressable (2.2.4)
ansi (1.4.1)
arel (2.2.1)
aws-s3 (0.6.2)
bcrypt-ruby (2.1.4)
builder (3.0.0)
bundler (1.0.21)
cocaine (0.2.1)
coffee-script (2.2.0)
coffee-script-source (1.2.0)
colorize (0.5.8)
daemons (1.1.5)
delayed_job (2.1.4)
devise (1.4.2)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.2.6)
faraday (0.6.1)
hashie (1.2.0)
hike (1.2.1)
hoe (2.12.5)
i18n (0.6.0)
jquery-rails (1.0.14)
json (1.6.5)
kaminari (0.12.4)
kgio (2.7.2)
libv8 (3.3.10.4 x86-linux)
machinist (2.0.0.beta2)
mail (2.3.0)
metaclass (0.0.1)
mime-types (1.17.2)
mocha (0.10.0)
multi_json (1.0.4)
multi_xml (0.2.2)
multipart-post (1.1.4)
mysql2 (0.3.6)
net-ldap (0.2.2)
newrelic_rpm (3.3.0)
nifty-generators (0.4.6)
nokogiri (1.4.7)
oa-basic (0.2.6)
oa-core (0.2.6)
oa-enterprise (0.2.6)
oa-more (0.2.6)
oa-oauth (0.2.6)
oa-openid (0.2.6)
oauth (0.4.5)
oauth2 (0.4.1)
omniauth (0.2.6)
orm_adapter (0.0.6)
polyglot (0.3.3)
pyu-ruby-sasl (0.0.3.3)
rack (1.3.6)
rack-cache (1.1)
rack-mount (0.8.3)
rack-openid (1.3.1)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.1.3)
railties (3.1.3)
raindrops (0.8.0)
rake (0.9.2.2)
rdoc (3.12)
rest-client (1.6.7)
riddle (1.5.1)
rspec (2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
rspec-mocks (2.6.0)
rspec-rails (2.6.1)
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
rubyntlm (0.1.1)
sass (3.1.12)
sass-rails (3.1.2)
sprockets (2.0.3)
SyslogLogger (1.4.0)
therubyracer (0.9.4)
thinking-sphinx (2.0.10)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
ts-delayed-delta (1.1.2)
turn (0.8.2)
tzinfo (0.3.31)
uglifier (1.0.3)
unicorn (4.1.1)
warden (1.0.6)
wkhtmltopdf (0.1.2)
xml-simple (1.1.1)

Twitter bootstrap typeahead difficult to add custom entries

 

If you are not familiar with twitter bootstrap typeahead please take a look at http://twitter.github.com/bootstrap/javascript.html#typeahead

While I am using twitter bootstrap, I found it is difficult to add the custom entries.

1 .When we add a entry and clicking on Enter the typeahead is taking the first list item as the value of the test box.

I solved this by Editing the typeahead javascript source code, refer my code from

https://github.com/abhilashak/Ajax-Typeahead

 

 

Two ways to load files in Rails

There are two ways that files get loaded in Rails:

It is registered in the autoload process, and you reference a constant that corresponds to the file name. For instance, if you have app/controllers/pages_controller.rb and reference PagesController, app/controllers/pages_controller.rb will automatically be loaded. This happens for a preset list of directories in the load path. This is a feature of Rails, and is not part of the normal Ruby load process.
Files are explicitly required. If a file is required, Ruby looks through the entire list of paths in your load paths, and find the first case where the file you required is in the load path. You can see the entire load path by inspecting $LOAD_PATH (an alias for $:).

Since lib is in your load path, you have two options: either name your files with the same names as the constants, so Rails will automatically pick them up when you reference the constant in question, or explicitly require the module.

I also notice that you might be confused about another thing. ApplicationController is not the root object in the system. Observe:

module MyModule
  def im_awesome
    puts "#{self} is so awesome"
  end
end
class ApplicationController < ActionController::Base
  include MyModule
end

class AnotherClass
end

AnotherClass.new.im_awesome
# NoMethodError: undefined method `im_awesome' for #

You will need to include the module into whatever class you want to use it in.

class AnotherClass
  include MyModule
end

AnotherClass.new.im_awesome
# AnotherClass is so awesome

Of course, in order to be able to include the module in the first place, you’ll need to have it available (using either of the techniques above).

Reference: This note is from a blog/site that I looked for some knowledge.

How to know your machine is 32 or 64 bit?

Here is an easy way to find this, in command line type

$ getconf LONG_BIT

Synopsis:

getconf [-v specification] system_var

the getconf utility shall write to the standard output the value of the variable specified by the system_var operand.

So it prints the value of ‘LONG_BIT’.

Read linux manual for getconf: http://linux.die.net/man/1/getconf