rails的一些琐碎的问题集棉

来源:互联网 发布:选创维网络电视 编辑:程序博客网 时间:2024/04/29 14:26
  1.  如何做一个无限循环,直到指定的条件满足,才就行其他的操作。问题的具体描述是这样的:现在需要判断一个文件是否存在,知道文件,才就行一些操作。
    Thread.new {            until File.exist?(File.join(Rails.root, "public", "video", pre_img))              sleep 1              logger.info("sleep:#{++i}")            end}
    until 循环控制

  2. 由字符串生成类,动态编程中特别需要
      self.channelable_type.downcase.capitalize.constantize.find_by_id(self.channelable_id)
  3. 将sublime-text放到可执行目录,就是/bin目录下,就可以在cmd的如何地方运行该程序了
    ln -s  /home/user/opt/sublime-text/sublime_text   /bin/sublime
    打开一个工程
    sublime  /var/www/pro
  4. send_file下载文件的中文问题的解决方法
          file_name = "#{video.user.username}_#{video.shot_time.strftime('%Y年%m月%d日%H时%M分')}_#{video.title}.flv"      real_file_name = Iconv.iconv("GB2312", "UTF-8", file_name)      send_file File.join(Rails.root,"public","video","#{video.url}"), :filename => real_file_name

  5. rails3 中取消test/unit的命令
    rails new project_name -T