`
RunUpwind
  • 浏览: 90356 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
在linux安装 savon 时,遇到这个错误。   yum install libxml2-devel   yum install libxslt-devel   之后,再gem install savon 成功!   参考:http://stackoverflow.com/questions/5881156/git-bundle-install-error-with-nokogiri-libxms2-is-missing
"Hello World".gsub("Hello", "Bye")  
在做编码转换时,遇了这个问题。原代码如下: str.encode('UTF-8') if str.encoding != 'UTF-8' 所以就遇到了错误:Encoding::UndefinedConversionError: "\xE5" from ASCII-8BIT to UTF-8     后来看了https://github.com/lassebunk/webcam_app/issues/1 将代码修改为以下,   str.force_encoding('UTF-8') if str.encoding != 'UTF-8' 这只是改了字符串的enc ...
我的环境: ruby -v 其中一台(32位):ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]    另一台(64位):ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]   rails -v Rails 3.0.5   安装rmagick,首先要安装ImageMagick ,用yum安装的可能是6.2 ...
gem install easy_captcha   文档在这里:  http://rubydoc.info/gems/easy_captcha/0.4.2/frames
如题,试用N种方法,终于找了一个可用的方法: http://www.waydotnet.com/blog/2010/02/rmagick-on-ruby-1-9-1=-i386-mingw32-work-d/   其中的环境变量设置那一步很重要,我第一次漏掉了,导致没有成功。  
参考:http://stackoverflow.com/questions/5111165/accessing-virtual-attribute-from-json   原本我这样写: @user.to_json(:only => [:id, :name, :pay_points])  后来我想增加一个属性,它不是一个数据库字段,是在@user中定义的一个方法: def points_value ...... end   我将to_json输出改成了: @user.to_json(:only => [:id, :name, :pay_poin ...
参见:http://stackoverflow.com/questions/2512450/time-now-created-at-are-different-ruby-on-rails   将config/application.rb 中的 config.time_zone =  前的注释去掉。改为: config.time_zone = 'Beijing'  即可。       2011-07-06更新: 虽然页面上显示的时间对了,但数据库存储的时间还是UTC时间,这会有些不便,怎样让数据库存储本地时间呢? config.active_record.defa ...
在做ROR开发时,经常要去查schema.rb, 确实有些不便。   《Web开发敏捷之道-应用Rails进行敏捷Web开发-第三版》中提到一个插件可将数据库信息添加到model顶端:annotate_models。   因为书中所讲内容已是过去时了,已经找不到那个plugn了。   google得知:现在有这样的GEM了: https://github.com/sagework/annotate_models   首先安装这个GEM: gem install annotate   然后在Gemfile里添加(重要): gem 'annotate'   到你的ROR ...
有一些配置,想通过WEB界面管理。但没有必要存入数据库,用yml文件方便些。   读文件比较简单: def self.get_config YAML::load(File.read(Rails.root.to_s + '/config/points_base_rules.yml')) end   读取对象之后,就可以显示在form上了,编辑之后,put 到server, server再将数据写入yml   写文件方法: def self.save(rules) result = true begin File.open(Rail ...
转自:http://augustl.com/blog/2010/ruby_net_http_cheat_sheet   I always have to look up how to use Net::HTTP , and I never find what I’m looking for. Behold, a cheat sheet! A basic request require "net/https" require "uri" uri = URI.parse("http://google.com") http ...
方法1:http://www.uedidea.com/rails%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86.html   def add_to_cart product = Product.find(params[:id]) rescue ActiveRecord::RecordNotFound #拦截Product.find()异常 logger.error("Attempt to access invalid product #{params[:id]}") #日志记录 flash[:notice] = "Invalid ...
参照:http://stackoverflow.com/questions/684457/how-do-you-clear-a-single-entry-from-a-ruby-on-rails-session http://stackoverflow.com/questions/2405635/how-to-empty-destroy-a-session-in-rails   清除session中的单个对象:   session[:foo] = nil session.delete :foo session.data.delete :foo   清除当前session ...
rails默认request的格式是 text/html.  同时还支持 xml 和 json.   如果要添加一个格式如.api,  访问路径:http://..../login.api,   该如何做?   参照:http://stackoverflow.com/questions/2456219/add-a-custom-format-in-rails-that-will-work-with-respond-to # add in Environment.rb Mime::Type.register "api/json", :api   在contro ...
server端:  参照:http://railscasts.com/episodes/82-http-basic-authentication   products_controller.rb before_filter :authenticate protected def authenticate authenticate_or_request_with_http_basic do |username, password| username == "foo" && password == "bar&q ...
Global site tag (gtag.js) - Google Analytics