lunes, 30 de noviembre de 2009

Active scaffold on ruby 1.8.7

If you have rails application 2.0.2 on ruby 1.8.6 and migrate your ruby to 1.8.7, but you have active scaffold working you will find some errors. So you need to change small code on active scaffold files. Here it goes

look for the file view_helper.rb

and change this line

@params_for[:controller] = '/' + @params_for[:controller] unless @params_for[:controller].first(1) == '/' # for namespaced controllers


to

  @params_for[:controller] = '/' + @params_for[:controller] unless @params_for[:controller].chars.first == '/' # for namespaced controllers


And you are done it works.

good luck.

sábado, 21 de noviembre de 2009

Compile Ruby 1.8.7-p174, on fedora 12

There is just one issue when compiling ruby on Fedora 12, and it has to do with openssl, ruby 1.8.7-p174 works fine with openssl 0.98 but not with openssl 1.0, so you need to find openssl 0.98  from  http://www.openssl.org/source/openssl-0.9.8l.tar.gz and compile it
tar xvzf openssl-0.9.8l.tar.gz
cd openssl-0.9.8l
./config
ls
make
make check
make install


miércoles, 21 de octubre de 2009

attachment_fu regenerate thumbnails

If you are using the attachment_fu plugin and for some reason you need to redo you thumbnails, then you need to know this definition that come as part of the pluging create_or_update_thumbnail(temp_file, file_name_suffix, *size)

for example:

On the console use the model

prod=Product.find(:all)

prod.each do | p|

p.create_or_update_thumbnail(RAILS_ROOT +'/public'+p.public_filename,:thumb,'300x300')

end

That is it will redo your thumbnail, of cource you can use it as you want. Enjoy!

viernes, 14 de agosto de 2009

Rails on share hosting environment

If you have a share hosting provider and you want to deploy a rails apps but you provider does not have rail on it or it has but not the specify rails version you require and you have ssh access to it, this steps may work for you

  1. Install ruby 1.8.7
    download ruby from ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz
    use wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz
    extract files tar xvzf ruby-1.8.7-p174.tar.gz
    change folder to ruby-1.8.7
    cd ruby-1.8.7
    change ruby configuration to install on the user folder
    ./configure --prefix=$HOME
    compile
    make
    make install

  2. Install ruby gems
    download gems from http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
    wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
    extract files tar xvzf rubygems-1.3.5.tgz
    change folder to cd rubygems-1.3.5
    execute and install the gems
    /home/tank/bin/ruby setup --prefix=$HOME
    this variable export GEM_HOME=/home/tank/ruby/gems
    (is best to set it on the user enviroment)
    you can do that adding it to your .bashrc or .bash_profile

  3. Install github if you need gems from github
    download github from http://www.kernel.org/pub/software/scm/git/git-1.6.4.tar.gz
    wget http://www.kernel.org/pub/software/scm/git/git-1.6.4.tar.gz
    extract tar xvzf git-1.6.4.tar.gz
    configure to install on the user home
    change to the git folder
    cd git-1.6.4
    ./configure --prefix=$HOME
    make
    make install

  4. Install you gems use like show here
    $HOME/bin/gem gem sources -a http://gems.github.com
    $HOME/bin/gem install mongrel
    $HOME/bin/gem install rails -v 2.3.2
    $HOME/bin/gem install mysql

  5. test your application
    go to you application folder and run
    $HOME/bin/ruby script/server
    6. to start the rails server you need to do this on your rails apps folder


  6. to start and stop rails server do
    $HOME/ruby/gems/bin/mongrel_rails mongrel::start -p 12004 --env=production -d -l log/mongrel.log
    $home/ruby/gems/bin/mongrel_rails mongrel::stop

  7. the .htaccess file on the the folder of the domain must have this lines this will redirect any web request from port 80 (http) to the 12004 port where our rails server is running.
    on this case the .htaccess file at $HOME/public_html/railsapps
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^mysite.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.mysite.com$
    RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:12004%{REQUEST_URI}" [P,QSA,L]
    RewriteRule ^(.*)$ "http\:\/\/127\.0\.0\.1\:12004%{REQUEST_URI}" [P,QSA,L]

One thing if you server does not have rails you can run ruby commands like gems, rails, rake with no need of adding the $HOME variable and bin path.

If you server has other version of ruby and rails then rake may not work it was not posible to make work so we have to relay on mysql command to create and load the application database.


Also i'm assuming you know or have the steps and gems require by your own rails apps.


Hope this help you, if not then get a VPS, where you can rule the machine, and this steps also may help you installing you ruby and rails but you need to consider not use mongrel and use passenger and not to use –prefix=$HOME when compiling.


Good luck.

domingo, 11 de enero de 2009

Upgrade to Rails 2.2.2

When you have work on an application on you favorite language or framework, it is always good to know the new features of new release of it. But it is not always easy to migrate all your work and effort to the new version, so for all of you who have done something on rails 2.0 here are some pointer to upgrade to rails 2.2.2

If your application is simple rails with no plugin or gems require the upgrade is simple:

First you need to upgrade you rails version, rails 2.2.2 require gems version 1.3.0, therefore you need to verify you gems version first to do so gem -v command to see the gems version, if you have gems version 1.3.0 or higher you are ready if not the you need to update your gem first, that can be accomplish by executing

gem update - - system

as root or

sudo gem update - - sytem

If that does not work, then you can download the gem code http://rubyforge.org/frs/?group_id=126 and do a manual upgrade. Once you have the right gems version you can do upgrade your gems by the command line:

gem update or sudo gem update

This will update all your installed gems including rails and its requirements.

Then on you rails application path type

rake rails:upgrade

This will update your rails application with the new rails version

Now you need to change your enviroment.rb file and change the rails version line from

RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION

to

RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION

When done you can start you server on development and see you application running with rails 2.2.2

If you have plugins you need to test and see if everything works as expected, some plugins like filecolum will break, giving you this error NameError (uninitialized constant FileColumn::ClassMethods::Inflector): it can be fixed by modifing the file file_column.rb from:
Inflector.underscore(self.name).to_s,

to
Activesupport::Inflector.underscore(self.name).to_s,


In active_merchand you need to comment out the infletor part of the file active_merchant/lib/active_merchant/billing/integrations.rb
In liquid you need to chage the ini.rb file to

ActionView::Base::register_template_handler :liquid, LiquidView 

to

ActionView::Template::register_template_handler :liquid, LiquidView   

If you have will_paginate as a plugin then you will have to remove it and use the gem version instead.

If you have started this project with rails 1.2.X and have used the pagination you will need to install classic_pagination plugin, but you will have to change this lines in order to make it work on rails 2.2.2
the file is pagination.rb
from
      options[:singular_name] ||= Inflector.singularize(collection_id.to_s) 
      options[:class_name]  ||= Inflector.camelize(options[:singular_name]) 
to
      options[:singular_name] ||= ActiveSupport::Inflector.singularize(collection_id.to_s)        options[:class_name]  ||= ActiveSupport::Inflector.camelize(options[:singular_name])