对于使用哪种Prototype助手感到困惑

在阅读http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html后,我似乎无法找到我正在寻找的东西。 我有一个简单的模型,在消息列表达到24之后删除最旧的消息,模型就这么简单: class Message ‘updated_at DESC’) messages[24..-1].each {|p| p.destroy } if messages.size >= 24 end end 消息列表下方有一个消息表单,用于添加新消息。 我正在使用Prototype / RJS将新消息添加到列表顶部。 create.rjs: page.insert_html :top, :messages, :partial => @message page[@message].visual_effect :grow #page[dom_id(@messages)].replace :partial => @message page[:message_form].reset 我的index.html.erb非常简单: @messages %> “message_form” %> 添加新邮件时,它们看起来很好,但是当达到24邮件限制时,它只是不断添加邮件而不删除旧邮件。 理想情况下,我希望它们随着新的添加而淡出,但它们可以消失。 create.rjs中的注释行实际上有效,它删除了过期的消息但是在添加新消息时我失去了视觉效果。 有没有人有一个关于如何完成添加和删除这个简单列表中的消息的建议? 非常感谢帮助。 谢谢阅读。 PS:在这种情况下,periodic_call_remote会有所帮助吗?

可以在Visual Studio 2008中添加Ruby语法高亮显示吗?

当我在Visual Studio中打开一个Ruby文件(* .rb)时,它会像常规文本文件一样读取 – 语言关键字上没有语法高亮显示。 有没有办法在Visual Studio中设置它? 更新:不,我不使用Visual Studio进行Ruby开发 – 我使用Netbeans。 但我想在Visual Studio中打开一个Ruby文件,看看正确的突出显示。

Ruby:对于bang方法,#map通常没有意义吗?

这个问题的灵感来自于这个问题: Ruby:为什么这种使用map的方式会引发错误? 有人指出以下内容: 使用时地图没有多大意义! 方法。 你应该: 使用gsub映射 或者使用每个gsub! 有人可以解释为什么会这样吗?

未定义的方法`+ @’表示false:FalseClass(NoMethodError)ruby

def next_prime_number (last_known_prime) while true last_known_prime++ found_factor = false # ERROR for i in 1…last_known_prime if last_known_prime % i == 0 found_factor = true break end end if !found_factor puts “new prime: #{last_known_prime}” Kernel.exit end end end in `next_prime_number’: undefined method `+@’ for false:FalseClass (NoMethodError) 我收到了上述错误,我完全被难住了。 任何想法(不,这不是功课,我试图通过欧拉项目自学Ruby)。

正则表达式以查找字符串中的第一个字母

考虑这个示例字符串: mystr =”1. moody” 我想将mystr中出现的第一个字母mystr 。 我在Ruby中尝试这个正则表达式,但仍然返回mystr (喜怒无常)中的所有字母而不是字母m。 puts mystr.scan(/[a-zA-Z]{1}/) 任何帮助赞赏!

我如何使用Ruby的SOAP :: Attachment类?

所以我正在为SOAP Web服务编写一个Ruby客户端,我已经想出了如何调用一个简单的方法: # WebServiceClient.rb require ‘soap/wsdlDriver’ wsdl_url = ‘http://urlmadness?wsdl’ service = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver result = service.simpleMethod(:sayHello => ‘Hello’) p result.return 现在我需要编写一些可以调用Web方法的东西,该方法期望附加文件作为SOAP MIME附件(SwA)。 我查看了Ruby的SOAP::Attachment类,但我似乎无法弄清楚如何使用它,我无法在任何地方找到任何示例。 有人知道如何使用它来为方法调用添加MIME附件吗? 谢谢, 亚历克斯

Array.find方法问题

我在ZenTest源代码中找到了这一行: result = @test_mappings.find { |file_re, ignored| filename =~ file_re } 这里的@test_mappings和result都是Array对象,但我没有在ruby doc的Array类中找到’find’方法。 我也尝试过irb: irb(main):014:0> Array.respond_to? :find => false irb(main):015:0> [1,2,3].find LocalJumpError: no block given from (irb):15:in `find’ from (irb):15:in `each’ from (irb):15:in `find’ from (irb):15 irb(main):016:0> [1,2,3].find{|x| x>1} => 2 任何人都可以向我解释一下吗? 怎么能找到方法还返回一个Array对象? 提前致谢。

如何两次调用rake目标

我通过修改.csproj文件以包含额外的编译符号,从我的.sln生成两组不同的DLL文件。 我正在使用rake构建解决方案,并具有以下构建任务: #========================================================== desc “Builds the DPSF.sln in Release mode.” msbuild :Build do |msb| puts ‘Building the DPSF solution…’ msb.properties :configuration => :Release msb.targets [:Clean, :Rebuild] msb.solution = DPSF_SOLUTION_FILE_PATH msb.parameters “/nologo”, “/maxcpucount”, “/fileLogger”, “/noconsolelogger” msb.verbosity = “quiet” # Use “diagnostic” instead of “quiet” for troubleshooting build problems. # Delete the build log file if the […]

TypeError:无法访问Mail :: Multibyte :: Chars

我最近在我们的Gemfile上更新了gem并开始获取: irb(main):002:0> User.new(:email => “foob@gmail.com”).valid? TypeError: Cannot visit Mail::Multibyte::Chars 用户模型: validates_uniqueness_of :email 如果我们关闭validation,一切正常。

相当于Ruby中的Python的findall()方法?

我需要从列表中的模糊列表中提取所有MP3标题。 使用Python,这对我很有用: import re for i in re.compile(‘mmc.+?mp3’).findall(open(“tracklist.txt”).read()): print i 我怎么能在Ruby中做到这一点?