Tagged: Ruby RSS

  • moonfox 12:24 am on May 26, 2010 Permalink | Log in to leave a Comment
    Tags: , Ruby   

    rails项目开发环境一定要与服务器生产环境一致 

    在使用ruby1.8.6时,发现字段串也有.last方法,即取出字符串的最后一位,后来在ruby1.8.7的环境下调用此代码,被告之没有定义last方法,查询api实确没有找到last方法,开发环境下使用的是ruby1.8.6版本,而ruby1.8.7是生产环境下的版本,还好发现的早,错误及时在发生前被终止。

    由于开发环境在windows下,所以使用的ruby版本为1.8.6二进制发行版,而服务器为linux环境,ruby版本为1.8.7,从而导致出现上述不兼容问题,所以开发环境务必要与生产环境一致,否则你写的每一行代码都将会成为一串串定时炸弹,不定在什么时候就会炸开, 所以为了我们项目的安全,我们在开发时的环境必须与服务器生产环境一致。

     
  • moonfox 9:28 pm on May 23, 2010 Permalink | Log in to leave a Comment
    Tags: , Ruby   

    ruby 安装 rmagick 

    sudo apt-get install libmagick9-dev ruby1.8-dev
    sudo apt-get install imagemagick
    sudo gem install rmagick

     
  • moonfox 11:05 pm on May 20, 2010 Permalink | Log in to leave a Comment
    Tags: Ruby   

    奇怪的ruby case 

    ruby中的条件判断语句case我们都不应该陌生吧,在view层使用时出现了这样一个怪现象。
    如果这样写
    <% case 条件表达示 %>
    <% when “条件1″%>

    标题

    <% when “条件2″%>

    标题

    <% end %>
    被告知有语法错误。
    如果写成

    <%

    case 条件表达示

    when “条件1″

    %>

    程序顺利通过。即将case 与第一个when写在一起,这时程序不会出错。难道分开放在<%%>里会出错。差点被这个bug折腾死!ORG

     
  • moonfox 6:21 pm on May 5, 2010 Permalink | Log in to leave a Comment
    Tags: , , Ruby   

    mysql 字符串转换成数字 

    在mysql中使用cast 函数将数字转换字符时,发现这样一个现象,将字符串“6,666”转换为数字时,预期值应该为6666,但实际值为6,并且rails的1.22版本也存在同样的问题。

    解决方法,很无奈,将“6,666”中的”,”去掉,再进行转换。

     
  • moonfox 12:30 am on May 4, 2010 Permalink | Log in to leave a Comment
    Tags: , Ruby   

    rails redirect_to 

    做了一个出错后跳转的页面,运行后发现程序进入死循环,查看日志发现页面被回指到了自己,原因是在redirect_to的时候自动继承了链接中的参数,由此得出结论,在带参数的情况下将页面回指到自己时,如果只指定了action,链接的参数会被自动继承,若要去掉参数,需要在redirect_to的时候重新定义。

     
  • moonfox 11:55 pm on April 25, 2010 Permalink | Log in to leave a Comment
    Tags: Ruby   

    ruby 类测试 

    如题

    ruby_test

     
  • moonfox 11:25 pm on March 14, 2010 Permalink | Log in to leave a Comment
    Tags: Ruby   

    小试重构 

    试着把开发项目的一个子模块重构了一下,可能也算不上重构,除了时间上比不重构时花的要长外,也更加的累人。难道是重构的思路不对?

     
  • moonfox 11:34 pm on March 1, 2010 Permalink | Log in to leave a Comment
    Tags: , Ruby   

    ruby 1.8.7 and rails 1.2.2完美匹配 

    由于ruby高版本的ruby与低版本的rails存在着兼容性问题,导致在不同的版本之间都有着这样或那样的问题,如(ruby1.8.7与rails 1.2.2就存在mysql接口调用问题),经过一番试验,发现ruby 1.8.7 (2009-06-12 patchlevel 174)与rails1.2.2有着良好的兼容性,目前还没有发现任何问题!

     
  • moonfox 10:10 pm on February 20, 2010 Permalink | Log in to leave a Comment
    Tags: , Ruby   

    ruby与rails版本差异不能连接mysql 

    由于ruby与rails版本差异,可能会出现在使用低版本的rails时,出现不能连接mysql的情况。
    现象:ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/vendor/mysql.rb:566:in `initialize’: wrong number of arguments (1 for 0) (ArgumentError)

    解决方法
    def scramble41(password, message)
    return 0×00.chr if password.nil? or password.empty?
    buf = [0x14]
    #s1 = Digest::SHA1.new(password).digest
    s1 = Digest::SHA1.new
    s1 << password
    s1 = s1.digest
    #s2 = Digest::SHA1.new(s1).digest
    s2 = Digest::SHA1.new << s1
    s2 = s2.digest
    #x = Digest::SHA1.new(message + s2).digest
    x = Digest::SHA1.new << (message + s2)
    x = x.digest
    (0..s1.length – 1).each {|i| buf.push(s1[i] ^ x[i])}
    buf.pack(“C*”)
    end

     
  • moonfox 6:33 pm on February 17, 2010 Permalink | Log in to leave a Comment
    Tags: , Ruby   

    image_tag(“icon”) # =>
    Icon
    image_tag(“icon.png”) # =>
    Icon
    image_tag(“icon.png”, :size => “16×10″, :alt => “Edit Entry”) # =>
    Edit Entry
    image_tag(“/icons/icon.gif”, :size => “16×16″) # =>
    Icon
    image_tag(“/icons/icon.gif”, :height => ’32′, :width => ’32′) # =>
    Icon
    image_tag(“/icons/icon.gif”, :class => “menu_icon”) # =>
    Icon
    image_tag(“mouse.png”, :mouseover => “/images/mouse_over.png”) # =>
    Mouse
    image_tag(“mouse.png”, :mouseover => image_path(“mouse_over.png”)) # =>
    Mouse

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel