Pages

How to set up ( Fedora php ruby on rails )

Monday, January 2, 2012

Android: How to include classes from other project from command line

How to add reference to an other android project(ANT)

Often we need to refer classes from other projects using eclipse is kinda easy and google will help you a lot in doing that, but here I am going to show how to include classed or refer other android project libs in your project

Suppose you have project one with a class Student with attribute name along with setter and getter and want to import Student class in second project, First you need to update project second to tell where to load files that can be done by
android update project --path ./ --library ./../SecondProject
if you debug your code now you probably will get exception because (probably) project one is not a library project. so you need to go to first project and update project.properties file and add android.library=true after target=your target
now compile the project all will go well.

Now you want to use the Student class from package one (com.package.one) is package name then you can use import com.package.one.Student; 

Sunday, June 12, 2011

Cpanel gems installation errors

You need ssh access to server to perform all these tasks


Did you get an errors like this when installing gems on cpanel



Missing these required gems:
will_paginate

You're running:
ruby 1.8.7.173 at /usr/bin/ruby
rubygems 1.3.5 at /home/bronze/ruby/gems, /usr/lib/ruby/gems/1.8/

Run `rake gems:install` to install the missing gems.


You need to add path in your .bashrc file



if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

export PATH=$PATH:$HOME/ruby/gems/bin
export GEM_PATH=$HOME/ruby/gems:/usr/lib/ruby/gems/1.8/
export GEM_HOME=$HOME/ruby/gems

And this to your config/environment.rb file



ENV['GEM_PATH'] = '/home/username/ruby/gems:/usr/lib/ruby/gems/1.8/'

Note:

Must replace username with your server username

What next


Source your .bashrc file or create new ssh session by logging out and logging in back


In most cases you won't have your .bashrc and .bash_profile file and you need this to make it work


Code for .bash_profile



if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

Wednesday, June 8, 2011

Encoding::UndefinedConversionError Ruby/Rails

Problem is you opening a binary file and writing it somewhere on other file using ruby/rails


Solution


open file as binary and write it back



File.open(target_file, 'w+b', 0644) do |file|
file.write(destination_file.data)
end

Sunday, February 20, 2011

How to remove Model Name from errors message in rails

Remove model/Table name from form errors


Here i am going to use regular expression to remove model/table name from my errors messages



<% @company.errors.full_messages.each do |msg| %>
<%= msg.gsub(/^\w+/, "").strip.capitalize %>
<% end %>

Tuesday, February 15, 2011

Development to Production db:migration

1. How to create tables in production environment from development


2. How to copy tables from development to production


this will only migrate tables structure from development to production


RAILS_ENV=production rake db:migrate

Monday, February 14, 2011

Rake Route(How to see routes of specific controller)

How to target specific controller in rake routes command


Most of time i need to look at my routes and as project increases so the list of routes and it's get confusing to find a specific routes using rake routes command so here is the answer


rake routes CONTROLLER=controller_name

For Example


rake routes CONTROLLER=posts

Thursday, December 30, 2010

CodeRay with Ruby On Rails 3

Code highlight in Ruby On Rails 3 Using CodeRay


First open your Gemfile and add


gem 'coderay'

and run bundle install


bundle install

Next you need to add a method any where you want best place would be ApplicationController




def coderay(text)
text.gsub(/<code( lang="(.+?)")?>(.+?)<\/code>/m) do
CodeRay.scan($3, $2).div(:css => :class)
end
end


Suppose you have controller Post and it's action show
app/controllers/posts_controller.rb



def show
@post = Post.find(params[:id])
@post.body = coderay(@post.body)
end


now in view file change following
app/views/posts/show.html.erb


<%= @post.body %>


To


<%= sanitize @post.body %>


Now you need a stylesheet that define color scheme for your code


span.af{/* attribute name fat */}
span.an{/* attribute name */}
span.av{/* attribute value */}
span.aw{/* attribute value fat */}
span.bi{/* bin */}
span.c{/* comment */}
span.ch{/* char */}
span.cl{/* class*/}
span.cr{/* colour */}
span.co{/* constant */}
span.cv{/* class variable */}
span.df{/* definition */}
span.di{/* directive */}
span.dl{/* delimeter */}
span.do{/* doc */}
span.ds{/* doc string */}
span.e{/* escape */}
span.er{/* error */}
span.ex{/* exception */}
span.fl{/* float */}
span.fu{/* function */}
span.gv{/* global variable */}
span.hx{/* hex */}
span.i{/* integer */}
span.ic{/* include */}
span.id{/* ident */}
span.il{/* inline */}
span.in{/* interpreted */}
span.iv{/* instance variable */}
span.k{/* content */}
span.ke{/* css attribute */}
span.kw{/* css selector */}
span.la{/* label */}
span.lv{/* local variable */}
span.mod{/* modifier */}
span.oc{/* oct */}
span.on{/* operator name */}
span.op{/* operator */}
span.pc{/* pre constant */}
span.pt{/* pre type */}
span.pd{/* predefined */}
span.pp{/* preprocessor */}
span.rx{/* reg exp */}
span.r{/* reserved */}
span.s{/* string */}
span.sh{/* shell */}
span.sp{/* space */}
span.sy{/* symbol */}
span.ta{/* tag */}
span.tf{/* tag fat */}
span.ts{/* tag special */}
span.ty{/* type */}
span.v{/* variable */}
span.vl{/* css value */}
span.xt{/* xml text */}