Posts

Showing posts from 2011

Ruby on Rails all installations in ubuntu

Ruby on Rails all installations in ubuntu #################################################### #                                                                                       # #      https://help.ubuntu.com/community/RubyOnRails           # #                                                                                       # ####################################################

PDFTron SDK for ruby Sample code

The sample code for PDFTron is giver separate for all languages http://www.pdftron.com/pdfnet/samplecode.html Click on ruby link in each topic for ruby code.

issue while installing rails_admin gem in ruby on rails

if we get the error while installing rails_admin for the error lib/rails_admin/config/fields/types.rb:11:in `load': Unsupported field datatype: binary (RuntimeError) we have to follow below code in config/initializers/rails_admin.rb since I don't display the binary field I put this monkey patch in my initializer: module RailsAdmin module Config module Fields module Types def self . load ( type ) return @@registry [ :text ] if ( type . to_sym == :binary ) @@registry [ type . to_sym ] or raise "Unsupported field datatype: #{ type } " end end end end end

Admin Interfaces for Rails Apps: RailsAdmin vs ActiveAdmin

The complete article is on http://batsov.com/articles/2011/11/20/admin-interfaces-for-rails-apps-railsadmin-vs-activeadmin/

What's the difference between "include" and "require" in Ruby?

The include and require methods do very different things. The require method does what include does in most other programming languages: run another file. It also tracks what you've required in the past and won't require the same file twice. To run another file without this added functionality, you can use the load method. The include method takes all the methods from another module and includes them into the current module. This is a language-level thing as opposed to a file-level thing as with require. The include method is the primary way to "extend" classes with other modules (usually referred to as mix-ins). For example, if your class defines the method "each", you can include the mixin module Enumerable and it can act as a collection. This can be confusing as the include verb is used very differently in other languages.

Difference between include and extend in Ruby on Rails

include   : mixes in specified module methods as   instance methods   in the target class extend   : mixes in specified module methods as   class methods   in the target class So is the major difference just this or is a bigger dragon lurking?   e.g. module ReusableModule   def module_method     puts "Module Method: Hi there!"   end end class ClassThatIncludes   include ReusableModule end class ClassThatExtends   extend ReusableModule end puts "Include" ClassThatIncludes . new . module_method       # "Module Method: Hi there!" puts "Extend" ClassThatExtends . module_method               # "Module Method: Hi there!"

How to Become a Computer Scientist

Computer scientists are the experts who push the boundaries of computer technology to find out how it can be improved and to help us better understand and make use of its potential. They may specialize in any of a wide range of subjects, including programming languages, hardware design, artificial intelligence, computer-human interaction and many others. Instructions 1 Take courses in high school such as computers, mathematics, science and English if you're interested in a career in computer science. 2 Take part in a placement or internship if you have the chance. You'll get to work alongside a computer scientist and see what their work environment is like. You will also get to note it as experience on your resume. 3 Obtain a bachelor's degree in computer science. Bachelor's degree programs tend to take four years to complete. Depending on the position you apply for, a degree in a related subject, such as computer engineer

Ruby on Rails Devise gem controller overrides and set routes for multiple controllers

In my ROR project I have overrides two controllers 1)registeration controller 2)session controller while setting routes for these In my routes.rb file I specified like this devise_for :users, :controllers => { :registrations => "registrations" } devise_for :users, :controllers => {:sessions => "sessions" } In above way It is not taking session controller by default it is going to Devise::sessionController just changed the routes in below way devise_for :users, :controllers => { :registrations => "registrations",:sessions => "sessions" } It is working fine.

Ruby on rails all

In following page you  can find all useful staff on rails http://railsapps.github.com/best-recommended-learning-rails-books-resources.html

RubyConf 2011 content documents and videos of speakers talks

Kindly follow the link to update your knowledge on ruby on rails ####################################### http://rubyconfindia.org/2011/talks.html #######################################

Ruby on rails fixers for testing

Fixtures  are a way of organizing data that you want to test against; in short, sample data. They come in 3 flavors: 1. YAML fixtures 2. CSV fixtures 3. Single-file fixtures For Detail information kindly follow the link #################################################### http://ar.rubyonrails.org/classes/Fixtures.html ####################################################

Streaming on ruby on rails

Follow the below link to analise Streaming on rails. ######################################################## http://api.rubyonrails.org/classes/ActionController/Streaming.html ########################################################

assets pipeline feature in rails 3.1.0

for assets pipeline documentation follow below link http://guides.rubyonrails.org/asset_pipeline.html

upgrade rails application to rails 3.1.0

Follow the below link to find guide http://davidjrice.co.uk/2011/05/25/how-to-upgrade-a-rails-application-to-version-3-1-0.html

Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) Error in Rails 3.1.0 rails s

Installing node.js fixed this for me go to https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager or run the following commands on your terminal sudo apt-get install python-software-properties sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs

How Do I Create And Publish My First Ruby Gem?

Link: http://rubylearning.com/blog/how-do-i-create-and-publish-my-first-ruby-gem/ (sent via Shareaholic-Publishers) ---- What's a Ruby Gem? To solve various problems with Ruby, you might develop your own libraries. Also, you might want to open-source your libraries to get help from the Ruby community and have many developers working on the same. A gem is a packaged Ruby application or library. RubyGems is the st

Send ajax request from jquery.

It is better to send Ajax requests directly from java script or jquery instead clicking on button from Java Script to send Ajax request. insecure https protocol IE shows some error if you send clicking on button from java script to send Ajax request Sample code:- $j.ajax({  type: "POST",   url: " https://myurl.com/recent "  data: "requstids="+response.request_ids   })

scp command usage guide

Example syntax for Secure Copy ( scp ) What is Secure Copy? scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh . Examples Copy the file "foobar.txt" from a remote host to the local host $ scp your_username@remotehost.edu:foobar.txt /some/local/directory Copy the file "foobar.txt" from the local host to a remote host $ scp foobar.txt your_username@remotehost.edu:/some/remote/directory Copy the directory "foo" from the local host to a remote host's directory "bar" $ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Mysql backup and restore

This tutorial explains the how to backup and restore the MySQL Database. Databases are used to store large amount of precious data and it becomes very important to Backup your data. In case case of some hardware or software failures  backup data can be used to restore the Database. Backing Up MySQL Database MySQL database backup can be accomplished in two ways: a) Copying the raw mysql database files & b) Exporting tables to text files Copying the MySQL database files MySQL uses the same table format on different platforms, so it's possible to copy MySQL table and index files from one platform and use them on another without any difficulties (assuming, of course, that you're using the same version of MySQL on both platforms). Exporting tables to text files The MySQLDump is handy utility that can be used to quickly backup th

Jquery AJAX not working with session It is not taking old session issue with solution .

In my rails application when I trigger a Ajax request with my javascript in below way $j.ajax({ type: "POST", url:" https://mydomain.com/requests ", data: "requstids="+response.request_ids }).done(function( msg ) { alert( "Data Saved: " + msg ); }); The request is firing correctly but it is not taking my old session values of user It is showing error that your session variable is not available in my log any idea why it is not taking previous session ? and how to fix that ? I got solution we need to add below code in your header javascript, which tells use browser cookie in server externally ############################################### $(document).ajaxSend(function(e, xhr, options) { var token = $("meta[name='csrf-token']").attr("content"); xhr.setRequestHeader("X-CSRF-Token", token); }); ################################################ normally by default xhr willnot sent session

Setting up SSL certificate locations in Linux for https:// in facebook application

After soo much struggling of openssl support for https:// I got solution for that simply we have to follow two steps 1) Install OpenSSL in your system         follow the below documentation for installing in ubonto     https://help.ubuntu.com/community/OpenSSL 2) Configure your omniauth.rb file to use those installed certificates     kindly follow the below documentation for configuring in your application    https://github.com/intridea/omniauth/wiki/Setting-up-SSL-certificate-locations-in-Linux  

start thin server in production eneveronment

thin start -e production -P tmp/pids/thin.3000.pid -p 3000 -d I would use RAILS_ENV=production bundle exec thin start ...

cucumber usage in rails project

Add below gems to your gem file $ gem'database_cleaner' $gem'cucumber-rails' $gem'cucumber' $gem'rspec-rails' Then run bundle install from your root directory. run rake db:migrate next run the below command in your project rails g cucumber:install --capybara $ above command will generate all necessary files run the below command to write cucumber stories to your application. $ touch features/support/your_test_file_name.rb go to the above file and write your application stories run below command to implement test cases for stories $ rake cucumber:wip now we can add the step defination for story in step_defination folder #features/step_definitions/yourcontroller_steps.rb Given /^a regexpress that is "(.*)"$/ do |color| Strawberry.make!(:color => color) end

how to run shall command for every particular interval

try the 'watch' command. Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>] [--no-title] [--version] <command> so that: watch -n1 command will run the command every second, forever OP has asked for link to OS X version of watch: http://www.macports.org/

Linux and Unix cp command

About cp Copies files from one location to another. Syntax cp [OPTION]... SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... --target-directory=DIRECTORY SOURCE... -a, --archive same as -dpR --backup[=CONTROL] make a backup of each existing destination file -b like --backup but does not accept an argument --copy-contents copy contents of special files when recursive -d same as --no-dereference --preserve=link --no-dereference never follow symbolic links -f, --force if an existing destination file cannot be opened, remove it and try again -i, --interactive prompt before overwrite

how to find unix is 64bit or 32bit

u can try in below three methods. >$ file /sbin/init /sbin/init: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.16, dynamically linked (uses shared libs), stripped >$ file /usr/bin/file /usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), stripped >$ uname -m x86_64

use of rake -T

rake -T will display the all available commands for rake tasks.

rake aborted! ,, Could not find a JavaScript runtime. See,https://github.com/sstephenson/execjs, for a list of available runtimes.

You need a javascript engine for rails 3.1 (heroku doesn't have one), and it appears that the javascript engine that works with Heroku is the rubyracer for heroku . Rails uses execjs to execute javascript and execjs supports 7 javascript engines. Node.js is one, and rubyracer is one. Gerred Dillon had a similar problem and wrote about it. In the comment section a point was raised about making this a production only change, since you already have nodejs as your local javascript engine. So the relevant code is: group : production do   gem 'therubyracer-heroku' , '0.8.1.pre3' end UPDATE: Heroku has a new stack, called Cedar , that they recommend for Rails 3.1.0. Heroku also has a doc about upgrading to Rails 3.1.0 rc5. They recommend not using 'therubyracer-heroku' gem anymore as it's not necessary with rc5. Also, make sure to update your config/application.rb file if yo

Active Record Migrations

Active Record Migrations Migrations can manage the evolution of a schema used by several physical databases. It’s a solution to the common problem of adding a field to make a new feature work in your local database, but being unsure of how to push that change to other developers and to the production server. With migrations, you can describe the transformations in self-contained classes that can be checked into version control systems and executed against another database that might be one, two, or five versions behind. Example of a simple migration: class AddSsl < ActiveRecord::Migration def up add_column : accounts , : ssl_enabled , : boolean , : default => 1 end def down remove_column : accounts , : ssl_enabled end end This migration will add a boolean flag to the accounts table and remove it i

How to remove big Facebooklogo in the starting of Application using omniauth gem

Rails.application.config.middleware.use OmniAuth::Builder do provider :facebook, 'YOURAPPID', 'YOURAPPSECRET', :iframe => true, :scope => "publish_stream,email,user_education_history" end # add this OmniAuth.config.full_host = ' http://apps.facebook.com/yourapp/ '

Caching in Rails

Image
you can find this documentation in http://blazingcloud.net/2010/11/21/caching-in-rails/ Caching in Rails In Rails we have two different ways of Caching - Page Caching: which is always stored on Disk - Action & Fragment Caching: which uses the configure cache configured in our Rails instance. By default Rails provides three techniques: 1) Page Caching Allows the request for a generated page to be fulfilled by the webserver, without ever having to go to your RoR application. In other words if you have page caching turned on,  the request will come in, go to Mongrel, the page will then be generated, and then sends  it back to apache.  Additionally,  it will be stored in a local file system. Next time we request the same page, apache will load the page from the filesystem and send it back to the client, without your Rails application being

Ruby on Rails usage big companies

I have seen all ruby on rails usage big companies in below three websites. http://blog.obiefernandez.com/content/2008/03/big-name-compan.html http://www.workingwithrails.com/high-profile-organisations http://rails100.pbworks.com/w/page/8815413/FrontPage

Ruby exception handling

begin result = risky_operation rescue StandardError => e puts "Risky operation FAILED: #{e}" end

Rspec Documentation

RSPEC RSpec is a great tool in the behavior driven design process of writing human readable specifications that direct and validate the development of your application. I've found the following practices helpful in writing elegant and maintainable specifications. First #describe What You Are Doing Begin by using #describe for each of the methods you plan on defining, passing the method’s name as the argument. For class method specs prefix a "." to the name, and for instance level specs prefix a "#". This follows standard Ruby documentation practices and will read well when output by the spec runner. describe User do describe '.authenticate' do end describe '.admins' do end describe '#admin?' do end describe '#name' do end end Then Establish The #context Next use #context to explain the different scenarios in which the method could be exe