botvector.net domain for sale $2k usd (negotiable). Em@il me t0: alex DOT creopolis at gmail DOT com

My Git activity

04 November 2009

Color is not a module in pdf-writer + rmagick SOLVED

Color is not a module
/usr/lib/ruby/gems/1.8/gems/color-1.4.0/lib/color.rb:19

Gems installed in application:
pdf-writer 1.1.8 + color 1.4.0 + color-tools 1.3.0
can happen to any pdf-writer version and in any OS (tested on XP/Ubuntu/Debian/FreeBSD)

I have two models:

#require "color"
require 'pdf/writer'
require 'pdf/writer/graphics'
require 'pdf/simpletable'
class ModelA

In this model i generate pdf's.


require 'RMagick'
include Magick
require 'rvg/rvg'
class ModelB

And in this model i generate images's.

Problem are raised when i added ModelB to project.
I was unable to use pdf generator(ModelA) as well as ModelB.

After some research i found that if i remove requires from ANY model, other model is working well ....

Temporary i removed ModelB requirements (generating images from another place).
Looking for solution ..

SOLVED

add
require "color"
BEFORE
require 'RMagick'
in ModelB so it will looks like:

require "color"
require 'RMagick'
include Magick
require 'rvg/rvg'
class ModelB


Magick should not to be on the toplevel.

27 May 2009

Update: 2.0.x to 2.3.2

Updating to 2.3.2 to get nice features ?
Thanks to all Rails Core team,

Now my own experience upgrating from 2.1.2 to 2.3.2:

Lets begin:
1/
READ THIS !!! MUST !!

2/
To update has_many_polymorphs go to here.

3/
To update output_compression plugin (output_compression.rb):
replace ActionController to Rack
replace class AbstractRequest to ActionController::Request

4/
To patch Globalize:
in vendor/pligins/globalize/lib/globalize/rails/action_view.rb
update:
alias_method :globalize_old_render_file, :render_file
to
alias_method :globalize_old_render_file, :render
AND
in /pligins/globalize/lib/globalize/localization/db_translate.rb
add :having key to options array
VALID_FIND_OPTIONS = ...
line 794 approximately.

x/
RUN:
rake rails:update

x/
Replace all render_file => "foo" to render :file => "foo" if any.

x/
Instead of config.action_controller.session = { :session_key => 'foo', ... use config.action_controller.session = { :key => 'foo', ....

x/
Use:
class ActionController::Request
instead of:
ActionController::AbstractRequest

and ruby script/server !
if anything ok, run your tests ..

Useful:
Rack module

Let me know if you encounter more "bugs" while patching to 2.3.2 ..

06 November 2008

Enhanced Migrations Plugin + Rails 2.1+

Hi,
In 2.1+ there are new migration style - it uses time stamp to create migration filename , just like Enhanced Migrations Plugin did.

Recently i updated my application to 2.1.2 (from 2.0.2) and found incompatibility with this plugin.

So we need to update our database!
We need take all Enhanced Migrations Plugin "migrations_info" and simply put them on schema_migration table !

First, backup your database.

Next:


DROP TABLE IF EXISTS schema_migrations;
CREATE TABLE schema_migrations (
version varchar(255) NOT NULL,
UNIQUE KEY unique_schema_migrations (version)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO schema_migrations (SELECT ID FROM migrations_info);
DROP TABLE migrations_info;


Now remove Enhanced Migrations Plugin from vendor/plugins,

And you're ready !

04 September 2008

Altering table

Adding and modifying table with Rails was never so easy and sexy !
You don't need to make tons of add_column for one type.. use change_table !!

and for def self.down use remove_column :table_name, [:column1, :column2 ...]

Add a column
 change_table(:suppliers) do |t|
t.column :name, :string, :limit => 60
end
Add 2 integer columns
 change_table(:suppliers) do |t|
t.integer :width, :height, :null => false, :default => 0
end
Add created_at/updated_at columns
 change_table(:suppliers) do |t|
t.timestamps
end
Add a foreign key column
 change_table(:suppliers) do |t|
t.references :company
end

Creates a company_id(integer) column

Add a polymorphic foreign key column
 change_table(:suppliers) do |t|
t.belongs_to :company, :polymorphic => true
end

Creates company_type(varchar) and company_id(integer) columns

Remove a column
 change_table(:suppliers) do |t|
t.remove :company
end
Remove several columns
 change_table(:suppliers) do |t|
t.remove :company_id
t.remove :width, :height
end
Remove an index
 change_table(:suppliers) do |t|
t.remove_index :company_id
end

HAVE FUN !!

28 August 2008

will_paginate on AJAX

Do you want will_paginate with AJAX functionality ?
Follow:

  1. Remove will_paginate plugin if you have it (/vendor/plugins/) /or backup it.
  2. in command line: gem sources -a http://gems.github.com
  3. in command line: gem install mislav-will_paginate
Now in config/environment.rb put after Initializer
Rails::Initializer.run do |config|
...
end

require 'will_paginate'
Next step, create new helper: remote_link_renderer.rb .. and copy&paste inside:


class RemoteLinkRenderer < WillPaginate::LinkRenderer
def prepare(collection, options, template)
@remote = options.delete(:remote) || {}
super
end
protected
def page_link(page, text, attributes = {})
@template.link_to_remote(text, {:url => url_for(page), :method => :get}.merge(@remote))
#replace :method => :post if you need POST action
end
end

Now, to ajaxize put:
<%= will_paginate :collection, :renderer => "RemoteLinkRenderer",:remote => {:with => "something_you_want", :update => "dom_id_element"} %>

And you are happy-ajax-paginator !
Sample:
<%= will_paginate @events, :renderer => "RemoteLinkRenderer",:remote => {, :update => "events_container", :loading => visual_effect(:appear, "loader"),:complete =>visual_effect(:fade,"loader" ) } %>
will call /events?page=x with AJAX request..
in my EventController:

respond_to do |format|
format.html { }
format.js { render :partial => "events" }
format.xml { render :xml => @events.to_xml }
end

Thats all !!
More info about will_paginate plugin here
Original post here

13 August 2008

acts_as_taggable_on_steroids + Globalize

Okay, situation is:

Parties involved: Rails 2.0.2, Globalize plugin, acts_as_taggable_on_steroids, ME.
(clickables) :)

Having model Event that translates :name, :body, :description with Globalize plugin.
Also Event are acts_as_taggable with acts_at_taggable_on_steroids ...

Ok for now, model works well, translated well, adding/removing/editing tags as well !

The problem is raise when we trying to @tags = Event.tag_cloud
we got :select option not allowed on translatable models (DISTINCT * FROM events .... !! THAT IS BADD !!!

Solution:
Open /ventor/plugin/acts_as_tabbable_on_steroids/lib/acts_as_taggable.rb
FIND:


LINE: 66
def find_tagged_with(*args)
options = find_options_for_find_tagged_with(*args)
options.blank? ? [] : find(:all, options)
end

CHANGE TO:

def find_tagged_with(*args)
options = find_options_for_find_tagged_with(*args)
options.blank? ? [] : untranslated_find(:all, options)
end


Restart server and you're done !

p.s. More info about great acts_as_taggable_on_steroid plugin is here.

09 August 2008

Dreamhost Hosting

Hi !

Personally i am hosting 3 websites working very well with dreamhost ( thru mod_rails & passanger), and its very easily to create new projects, svn repositories, mysql, custom gem packs, etc... everything You need for Rails site.

SOO if you want fast and cheap rails hosting check Dreamhost !
I would recommend basic plan(its really enought for hosting rails!),
I can give You free LIFETIME domain registration(domain never expires and You NEVER pay for him) !
This discount give's You upon NEW registration.
Plus i give You:
10$ off for monthly hosting plan,
25$ off for one year plan,
40$ (!) off for two year plan,

So get yourself promotional code BOTVECTORCX on DREAMHOST (click here)
(free lifetime domain + hosting discounts), enter promotional code in bottom of registration form to redeem $$$$$$ !
Have Fun !!! :)


p.s. If you need more specific code let me know ;)

25 June 2008

Authorization plugin addon

Hi ppl,

If you are using Authorization plugin (http://www.writertopia.com/developers/authorization) you can easily extend your ApplicationHelper with all benefits of authorization plugin.

Perhaps we have user "doomer" logged in, who have two roles > "tester" and "translator"
So regularly in some controller/action we can do:
current_user.has_role?("tester") // true
or
current_user.has_role?("admin") // false

and so on.
This is very nice usage of authorization stuff ! A big respect to billkatz and glenn.rempe.
However we want to ease usage of current....("admin") queries
We can do the following:
in application_helper


module ApplicationHelper
def tester?
current_user.has_role?("tester")
end
def admin?
current_user.has_role?("admin")
end
end
those methods will return true or false depends on user permission, but if we have 5+ roles ? +10 ? let me say its very dirty and wet way..

So lets do it:
open application.rb

def assign_roles
for role in Role.find(:all, :select => "name", :group => "name")
logged_in? ? r = current_user.has_role?(role.name) : r = false
c = "def #{role.name}?() #{r} end"
ApplicationHelper.module_eval(c)
logger.info "PARSED ROLE #{role.name}"
end
end

And for the last, put before_filter :assign_roles in begin of application.rb
Thats it !!
Okay what we did here ? >>
1. return if current_user isnt logged in (plugin method)
2. find all roles & create local r with true/false, depends on permission
3. create def code for ApplicationHelper and eval it.
We created exactly the same as above sample but much more dynamic & DRY !!

Thats all, have a fun usage !!!

p.s. an authorization plugin usage/download available here:
http://www.writertopia.com/developers/authorization
or from GIT:
http://github.com/DocSavage/rails-authorization-plugin/tree/master

ADDON--
If you want those helper methods to be available to controllers(because you CANT call helper method from controller) just add:
ApplicationController.module_eval(c)
under ApplicationHelper.module_eval(c)

This will create application controller methods (def admin? false end)