Showing posts with label Rails. Show all posts
Showing posts with label Rails. Show all posts

2009-10-01

Setting up Aptana

Installing Aptana on UNIX, Linux and OSX
Download AptanaStudio.
Follow the steps to complete plugin installation when you run it.
&] sudo cp ~/Downloads/Aptana_Studio_Setup_Linux_x86_1.5.1.zip /Applications/ ; cd /Applications/
&] sudo unzip Aptana_Studio_Setup_Linux_x86_1.5.1.zip
&] sudo ln -s Aptana\ Studio\ 1.5 AptanaStudio
&] sudo chmod -R +x AptanaStudio
&] sudo chown -R root:enrique Aptana*

Installing Aptana on Windows
Download AptanaStudio.
Follow the steps to complete plugin installation when you run it.

2009-09-09

Using rsruby in RubyOnRails

  1. Create your Rails application
  2. Let’s call it Plotter. Usual procedure:
    rails Plotter
    cd Plotter
    rake db:create
    We won’t use the database (default sqlite3) in this example, but you may use it later on.
  3. Tell the application about R_HOME
  4. RSRuby will fail unless the environment variable R_HOME is set.
    To tell Plotter that R_HOME is /usr/lib/R, I put this in the file app/helpers/application_helper.rb:
    module ApplicationHelper
    # set R_HOME if not set
    if ENV['R_HOME'].nil?
    ENV['R_HOME'] = "/usr/lib/R"
    end
    end
  5. Make an instance of RSRuby available to all controllers
  6. RSRuby works by providing an instance of an “R object”, on which you call R functions as methods.
    I provided the object by editing app/controllers/application_controller.rb to include a method named InitR:
    class ApplicationController < r =" RSRuby.instance">
    
  7. Create a sample controller and view
  8. For testing purposes, I created a controller named Home with a single view named index:
    ./script/generate controller Home index
    rm public/index.html
    I edited config/routes.rb so as the root of the application is the index view for the home controller:
    ActionController::Routing::Routes.draw do |map|
    map.root      :controller => "home"  #default view is app/views/home/index.html.erb
    map.connect  ':controller/:action/:id'
    map.connect  ':controller/:action/:id.:format'
    end
    Now we can get to work on the file app/controllers/home_controller.rb. I wrote a sample method, show_image to plot a histogram using R via RSRuby:
      def show_image
    # next 6 lines use R to plot a histogram
    @r = InitR()
    @d = @r.rnorm(1000)
    @l = @r.range(-4,4,@d)
    @r.png "/tmp/plot.png"
    @r.par(:bg => "cornsilk")
    @r.hist(@d, :range => @l, :col => "lavender", :main => "My Plot")
    @r.eval_R("dev.off()")  #required for png output
    # then read the png file and deliver it to the browser
    @g = File.open("/tmp/plot.png", "rb") {|@f| @f.read}
    send_data @g, :type=>"image/png", :disposition=>'inline'
    end
    Not the prettiest code, but you get the idea. Obviously the owner of the HTTP daemon (www-data on Ubuntu) must have write permission to the location of the PNG file; /tmp in this case.
  9. Create the view
  10. All that remains is to edit app/views/home/index.html.erb so as it displays the image:

    Home#index

    Find me in app/views/home/index.html.erb <%= image_tag(url_for(:controller => "home", :action => "show_image")) %>
    Which just says “wrap whatever comes out of the method show_image in an IMG SRC tag”.

Installing BioRails

"BioRails":http:/projects/show/core is a commercially backed, open-source biological information management system designed specifically for pharmaceutical discovery research. BioRails core version is available free to use and the source code is available for download under the GNU Public License. Support services are available from "The Edge Software Consultancy Ltd":http//edgesoftwareconsultancy.com


This is a new BioRails Release Version at BioRails.org .

There is an example chemreg .

All support is now on BioRails.com .

You can start setting your development installation.

&] sudo apt-get install build-essential mysql-server mysql-client subversion ruby libzlib-ruby rdoc eruby irb libsvn-ruby ri libmysql-ruby libdbd-mysql-ruby imagemagick libmagick9-dev librmagick-ruby graphviz ruby1.8-dev libmysqlclient15-dev openssl htmldoc gnuplot rake zip sqlite3 libsqlite3-dev mongrel libruby-extras libxml2 libxml2-dev libxslt1-dev openoffice.org python-uno unoconv openoffice.org-dev

OpenOffice is needed so you can install the following packages:

&] sudo apt-get install openoffice.org openoffice.org-base openoffice.org-base-core openoffice.org-calc openoffice.org-common openoffice.org-core openoffice.org-dev openoffice.org-draw openoffice.org-filter-binfilter openoffice.org-mobiledev unoconv python-uno openoffice.org-headless

Gems is needed:

&] sudo gem install archive-tar-minitar builder chronic crypt fastercsv gnuplot hpricot htmldoc icalendar json mime-types mocha mongrel mongrel_cluster mysql ntp rcov rmagick mini_magick roodi rspec ruby-net-ldap rubyzip ruport sqlite3-ruby tidy transaction-simple tzinfo uuid uuidtools ZenTest

&] gem sources -a http://gems.github.com

&] sudo gem install mislav-will_paginate

&] gem list --local

&] sudo gem update

It is time to install source code.

For development:

&] mkdir trunk; svn co http://biorails.org/svn/biorails/core/trunk trunk/

For snapshot:

&] wget http://redmine.biorails.org/attachments/download/221?filename=biorails-3.0-2772.tar.gz ; tar -zvxf biorails-3.0-2772.tar.gz

Database connection:

&] cp config/database_template.yml config/database.yml ; nano config/database.yml

development:
adapter: mysql
database: biorails_development
username: biorails
password: moose
host: localhost

test:
adapter: mysql
database: biorails_test
username: biorails
password: moose
host: localhost

production:
adapter: oracle
database: localhost
username: biorails_validation
password: moose


/* Will need to login to mysql as root to initial run this script eg.
* mysql -u root -p
*/
create user biorails identified by 'moose';
create user 'biorails'@'localhost' identified by 'moose';

create database biorails_development;
grant all on biorails_development.* to 'root'@'localhost';
grant all on biorails_development.* to 'biorails'@'localhost';

create database biorails_test;
grant all on biorails_test.* to 'root'@'localhost';
grant all on biorails_test.* to 'biorails'@'localhost';

create database biorails_production;
grant all on biorails_production.* to 'root'@'localhost';
grant all on biorails_production.* to 'biorails'@'localhost';


&] mysql -u root -p < db/create_databases.mysql
grant all on biorails_production.* to 'biorails'@'localhost';

Create schema:

&] rake db:schema:load ; rake -T

Quick check:

&] rake biorails:check:all

Test preparation:

&] unoconv -l

Full test:

&] export RAILS_ENV=test
&] rake biorails:ferret_start
&] rake test

Bootstrap:

&] rake biorails:db:bootstrap
&] ruby script/server


Lighthttpd web server:

&] sudo apt-get install lighttpd
&] nano config/lighttpd-template.conf
########################################################################
# lighttpd configuration file
#
# use it as a base for lighttpd 1.0.0 and above
#
# $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $
#
############ Options you really have to take care of ####################
server.modules = ("mod_rewrite", "mod_access", "mod_redirect", "mod_proxy", "mod_compress", "mod_accesslog")
server.document-root = "/home/biorails/enterprise/trunk/public/"
server.errorlog = "/var/log/lighttpd/error_log"
server.dir-listing = "disable"

## files to check for if .../ is requested
server.indexfiles = ("index.html", "index.htm", "index.rb")

&] sudo cp config/lighttpd-template.conf /etc/lighttpd/lighttpd.conf
&] sudo /etc/init.d/lighttpd stop
&] sudo lighttpd -f /etc/lighttpd/lighttpd.conf

Performance upgrade:
&] export RAILS_ENV=production
&] rake asset:packager:build_all
&] rake biorails:start


HTMLCode

HTMLCode Content