Showing posts with label Problem. Show all posts
Showing posts with label Problem. Show all posts

Tuesday, November 27, 2007

PHP/Mysql新版本安装问题

php安装了不知道多少次,经常会碰到一些安装问题,这次装5.2.5碰到2个错误如下:
configure: error: xml2-config not found. Please check your libxml2 installation
在CentOS5.0中执行以下命令:
$> yum install libxml2-devel

接下来又有新问题了(用rpm包装的mysql server 5.1.22):
Note that the MySQL client library is not bundled anymore!

configure: error: Cannot find MySQL header files under /usr/shared/mysql.
Note that the MySQL client library is not bundled anymore.
ERROR: Could not configure PHP

到mysql官网下载对应的5.1.22 mysql-devel开发包,安装完再装PHP即可。

Thursday, November 15, 2007

因为iframe标签关闭不正确造成的问题

<iframe src="http://www.baidu.com"/>
因为iframe标签关闭不正确,后面的Javascript和此文本内容在FF/IE上(其他浏览器未测试)都不会被执行,HTML输出流截止于iframe。
<script type="text/javascript">
alert('test');
</script>

Wednesday, November 14, 2007

Jruby on rails 安装中的问题

在安装好jdk和jruby后并测试jruby正常工作后,设置了几个命令别名,以防跟原来系统装的ruby命令冲突,ruby下的irb/rails/gem/ruby等命令是包含到系统中的。Jruby要以示区别:
$> vi .bashrc
alias jgem='/usr/local/jruby/bin/gem'
alias jruby='/usr/local/jruby/bin/jruby'
alias jrails='/usr/local/jruby/bin/rails'
alias jirb='/usr/local/jruby/bin/irb'
alias jrake='/usr/local/jruby/bin/rake'

重新登录后,jruby正常工作,但jgem报错,Google无果。只能命令行调jruby安装rails到Jruby环境下,-S cmd run the specified command in JRuby's bin dir。
$> jgem -v
/usr/bin/env: jruby -J-Xmx512M: No such file or directory
$> jruby -J-Xmx384m -S gem install rails --version 1.2.3 --include-dependencies
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-1.2.3
Successfully installed activesupport-1.4.2
Successfully installed activerecord-1.15.3
Successfully installed actionpack-1.13.3
Successfully installed actionmailer-1.3.3
Successfully installed actionwebservice-1.2.3
Installing ri documentation for activesupport-1.4.2...
Installing ri documentation for activerecord-1.15.3...
....
新建Jrails项目如下:
$> jruby -S rails test
却不能用 $> jrails test
报错如下:
/usr/local/jruby/bin/rails: line 9: require: command not found
/usr/local/jruby/bin/rails: line 10: version: command not found
/usr/local/jruby/bin/rails: line 11: syntax error near unexpected token `('
/usr/local/jruby/bin/rails: line 11: `if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then'
哪位仁兄如果看到此问题并有解决方案请跟贴指点,谢谢。
另附mongrel+jruby的windows安装过程:
$> jruby -S gem install mongrel --include-dependencies
$> jruby -S gem install gem_plugin
$> jruby -S gem install cgi_multipart_eof_fix
$> jruby -S gem install mongrel-1.1.1-jruby
ERROR: While executing gem ... (OpenURI::HTTPError)
404 Not Found
# Why can't install gem package from rubyforge? Make sure to invoke the command from the directory where the gem is downloaded.
$> wget http://rubyforge.org/frs/download.php/27884/mongrel-1.1.1-jruby.gem
$> jruby -S gem install mongrel-1.1.1-jruby
$> wget http://rubyforge.org/frs/download.php/20455/mongrel_jcluster-0.0.1.gem
$> jruby -S gem install mongrel_jcluster-0.0.1
# mongrel_cluster does not work with JRuby and mongrel_jcluster does not work on Windows. So Mongrel clusters cannot be configured on a Windows machine.
=================================================================================
$> wget http://rubyforge.org/frs/download.php/21765/hpricot-0.6-jruby.gem
$> jruby -S gem install hpricot-0.6-jruby
$> jruby -S gem install mechanize # not install scrubyt will raise error about openssl
$> jruby -S gem install scrubyt --include-dependencies # need install this gem package for using mechanize
$> wget http://rubyforge.org/frs/download.php/24515/ActiveRecord-JDBC-0.5.gem
$> jruby -S gem install ActiveRecord-JDBC-0.5
$> wget http://rubyforge.org/frs/download.php/23995/jruby-openssl-0.0.4.gem
$> jruby -S gem install jruby-openssl-0.0.4

Thursday, November 08, 2007

Rails development environment problem

在开发模式下,Rails的Models里的文件修改后会自动重载入,但是Models里require进来的Ruby lib和Rails lib下的文件有所修改是不会自动重载入的,必须需要重启Rails应该。

Sunday, August 26, 2007

Rails Routes 详解

$>cd RubyOnRails/app/path
$>cd script/console
>>rs = ActionController::Routing::Routes
>>puts rs.routes
ANY /:controller/service.wsdl/ {:action=>"wsdl"}
ANY /:controller/:action/:id.:format/ {}
ANY /:controller/:action/:id/ {}
=>nil

修改config/routes.rb文件,添加一行
map.connect 'modules/controller/:action/*other', :controller => 'modules/controller'
回到console
>>rs.reload
>>puts rs.routes
ANY /:controller/service.wsdl/ {:action=>"wsdl"}
ANY /:controller/:action/:id.:format/ {}
ANY /:controller/:action/:id/ {}
ANY /modules/controller/:action/:other/ {:controller=>"modules/controller"}
=>nil
>>rs.recognize_path '/modules/controller/test/2?x=1'
=>{:action=>"test", :other=>["2?x=1"], :controller=>"modules/controller"}
>>rs.recognize_path '/test/action/1'
=>{:action=>"action", :id=>"1", :controller=>"test"}
>> rs.add_route('/x/y/z', {:controller => 'test', :action => 'index', :id => 0})=> #>>puts rs.routes
ANY /:controller/service.wsdl/ {:action=>"wsdl"}
ANY /:controller/:action/:id.:format/ {}
ANY /:controller/:action/:id/ {}
ANY /modules/controller/:action/:other/ {:controller=>"modules/controller"}
ANY /x/y/z/ {:action=>"index", :id=>0, :controller=>"test"}
=> nil
>> rs.draw do |map|
?> map.connect '/blog/:id', :controller => 'blog', :action => 'list'
>> end
=> [ActionController::Base, ActionView::Base]
>> puts rs.routes
ANY /blog/:id/ {:action=>"list", :controller=>"blog"}
=> nil
>> rs.recognize_path '/blog/1'
=> {:action=>"list", :id=>"1", :controller=>"blog"}
这里发现原来的routes全部不见了,只有这个新建的routes了,因为draw方法内部实现为:


def draw
clear!
yield Mapper.new(self)
named_routes.install
end

draw方法块里的map对象里method_missing方法就是用来实现具名路由named routes的。先看下源码如下:

def method_missing(route_name, *args, &proc)
super unless args.length >= 1 && proc.nil?
@set.add_named_route(route_name, *args)
end

上面对实例变量@set就是前面的rs对象,那么就看一下rs.add_named_route方法吧
>>rs.clear!
>>rs.add_named_route('index', 'user/index', :controller => 'user', :action => 'index')
puts rs.named_routes
#
=> nil
>> puts rs.routes
ANY /user/index/ {:action=>"index", :controller=>"user"}
=> nil
>> puts rs.named_routes.routes
indexANY /user/index/ {:action=>"index", :controller=>"user"}
=> nil
定义了具名路后就可以在controller/view中像url_for一样调用,只要在route name后面加上_url就可以,url_for在console里不能调试,可以用rs.generate(request)方法测试。
# In addition to providing url_for, named routes are also accessible after including UrlWriter.
url_for(:controller => 'signup', action => 'index', :token => token)
index_url(:id => 1)
#=> http://localhost/user/index?id=1
>> rs.generate(:controller => 'test', :action => 'index', :id => 3)
=> "/test/index/3"
另外在map这个对象里有个方法root可以给根目录定义路径,用法如下:

>> rs.draw do |map|
?> map.root :controller => 'test', :action => 'list'
>> end
ArgumentError: Illegal route: the :controller must be specified!
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:965:in `build'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1172:in `add_route'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1178:in `add_named_route'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:997:in `root_without_deprecation'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/deprecation.rb:94:in `root'
from (irb):60
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1139:in `draw'
from (irb):59


# Added deprecation notice for anyone who already added a named route called "root".
# It'll be used as a shortcut for map.connect '' in Rails 2.0.
# def root(*args, &proc)
# super unless args.length >= 1 && proc.nil?
# @set.add_named_route("root", *args)
# end
# deprecate :root => "(as the the label for a named route) will become a shortcut for map.connect '', so find another name"

Rails2.0才会引进此方法,所以Rails建议用户不要使用此具名路由,如下:
>> rs.draw do |map|
?> map.root '', :controller => 'test', :action => 'list'
>> end
=> [ActionController::Base, ActionView::Base]
>> puts rs.routes
ANY / {:action=>"list", :controller=>"test"}
=> nil
>> puts rs.named_routes.routes
rootANY / {:action=>"list", :controller=>"test"}
=> nil
这个写法其实就是做了个具名路由,而不是调用map.root方法,调用的是method_missing方法。

Thursday, August 16, 2007

用Ruby spreadsheet/excel 生成Excel文档(附问题)

require "rubygems"
require "spreadsheet/excel"
include Spreadsheet

workbook = Excel.new("test.xls")

format = Format.new
format.color = "green"
format.bold = true

worksheet = workbook.add_worksheet
worksheet.write(0, 0, "Hello", format)
worksheet.write(1, 1, ["Matz","Larry","Guido"])

workbook.close

这是doc里的例子,但是format并不能应用到"Hello"这个格子上,需要用format = workbook.add_format(:color => "green", :bold => true)才能真正生效,有知道原因的朋友可以回帖知会一下,谢谢。
PS: 这个lib只能生成,读取用parseexcel这个lib。