Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
欲登高
@huopo125
会员
第 8596 位会员 / 2013-08-09

[email protected]
上海
13 篇帖子 / 127 条回帖
7 关注者
9 正在关注
370 收藏
GitHub Public Repos
More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • mailcatcher 如何部署到生产环境? at 2015年03月24日

    #3 楼 @tracyzhang 不太一样, 如 [email protected],your_email 为 [email protected],username 为 example

  • mailcatcher 如何部署到生产环境? at 2015年03月24日

    Devise 设置

    # user.rb + confirmable
    devise :database_authenticatable, :registerable,
            :recoverable, :rememberable, :trackable, :validatable, :confirmable
    # migration
         ## Confirmable
         t.string   :confirmation_token
         t.datetime :confirmed_at
         t.datetime :confirmation_sent_at
         t.string   :unconfirmed_email # Only if using reconfirmable
         add_index :users, :confirmation_token,   unique: true
    # devise.rb
     config.mailer_sender = '<your_email>'
     # Configure the class responsible to send e-mails.
     config.mailer = 'Devise::Mailer'
    

    Mailer 设置 Gmail 设置请查看Guides

    # production.rb
     config.action_mailer.delivery_method = :smtp
     config.action_mailer.smtp_settings = {
       address: 'smtp.163.com',
       port: 25,
       domain: 'mail.163.com',
       user_name: '<username>',
       password: '<password>',
       authentication: :login
     }
    
  • 我用的是 rolify 的一个 gem 包,我在更新用户角色的时候,用户的角色居然删除了 at 2015年03月24日

    应该是你设置的 role,关联的 user 数量为 0,rolify 自动帮你清除掉了code

    def remove(relation, role_name, resource = nil)
      cond = { :name => role_name }
      cond[:resource_type] = (resource.is_a?(Class) ? resource.to_s : resource.class.name) if resource
      cond[:resource_id] = resource.id if resource && !resource.is_a?(Class)
      roles = relation.roles.where(cond)
      if roles
        relation.roles.delete(roles)
        roles.each do |role|
          role.destroy if role.send(ActiveSupport::Inflector.demodulize(user_class).tableize.to_sym).limit(1).empty?
        end if Rolify.remove_role_if_empty
      end
      roles
    end
    
  • 数据关联 through,到底用什么用?为什么我感觉是多余的。 at 2015年03月24日

    #4 楼 @drine 若你不需要反过来查到关联,可以不写;belongs_to 添加了以下一些方法:

    A Post class declares belongs_to :author, which will add:
    
        Post#author (similar to Author.find(author_id))
    
        Post#author=(author) (similar to post.author_id = author.id)
    
        Post#build_author (similar to post.author = Author.new)
    
        Post#create_author (similar to post.author = Author.new; post.author.save; post.author)
    
        Post#create_author! (similar to post.author = Author.new; post.author.save!; post.author)
    
    
  • Docker 入门 at 2015年03月23日

    #7 楼 @xiaozi0lei 谢了

  • 如何把网络上的负能量转化成正能量? at 2015年03月23日

    #5 楼 @jex 哦,应该是直接从输入法输入的问题,奇怪,我这边怎么显示正常呀,

  • 一个用 Rails 做 API server 的好例子 at 2015年03月23日

    :plus1: 正需要

  • 如何把网络上的负能量转化成正能量? at 2015年03月23日

    #3 楼 @jex 功能不错呀,顺便也学习一下你的代码,, 😄

  • 如何把网络上的负能量转化成正能量? at 2015年03月23日

    👍

  • 透彻理解 Ruby 中的 return at 2015年03月23日

    👍 学习了,pry 中_ex_

  • Docker 入门 at 2015年03月23日

    👍 ,希望 LZ 列出来一个能够直接帮助 Rails 开发的实例,总感觉原理概念什么的是使用之后的事情了

  • 大家最开始学 RoR 的时候,每本教程都读了几遍?是如何入门的呢? at 2015年03月23日

    其实感觉最快的就是,找一个做这方面的朋友,让他给你稍微讲讲 ruby on rails tutorial,,然后就是把自己脑袋里面能问的全部问题,全部掏出来晒晒,应该很快就入门了,当然了自己鼓捣也是可以,就是慢点,也会忽略掉一些重要的知识。。。

  • rails 如何换成 mysql 数据库 at 2015年03月23日

    可以换, 😄 需要装 mysql,这样本地调试方便,

  • 2015年3月29日 Rubyist 上海 2015 Q1 聚会 at 2015年03月20日

    :plus1:

  • UCloud API 开发大赛在 RubyChina 的特别抽奖送书活动,截止日期 3 月 24 日 at 2015年03月20日

    63 😄

  • Rails 应用在虚拟机里 Ubuntu Server 跑起来了,但是本地主机无法访问是什么原因? at 2015年03月19日

    😄,添加个原因,以备后用:

    Running Rack apps on 0.0.0.0 in development mode will allow malicious users on the local network (exf: a Coffee Shop or a Conference) to abuse or potentially exploit the app.Safer to default host to localhost when in development mode.

  • 关于 Rails 的 bundle 的疑问 at 2015年03月19日

    若你想查看当前项目的某个 gem 包安装位置:bundle show gem_name 若你想单独更新一个 gem 包,而不像修改 gemfile 和 gemfile.lock:bundle update gem_name

  • Nginx Passenger 部署问题 - Cannot execute /root/.rbenv/shims/ruby: Permission denied (13) at 2015年03月19日

    你可以直接将部署时 capitstrano 执行的最后出错命令,到你主机上直接执行进行调试。这类问题挺折腾的,所以以后还是将所有环境装在你部署时使用的用户环境中的好。

  • 继续开源 partake.top at 2015年03月19日

    :plus1:

  • 对为什么 bundle install 要加上 without production 有一点疑问 at 2015年03月17日

    你的理解正确,可参考:https://ruby-china.org/topics/1050

  • 上周开发的一款 Markdown 编辑器: Markdown Plus at 2015年03月16日

    😄 star

  • [杭州] 阿里巴巴招两名 Ruby 工程师 at 2015年03月16日

    看到这,只能默默的努力了....1.. 😄

  • starry.so 开源出来了 at 2015年03月13日

    :plus1: 不错,,

  • 我如何读书 at 2015年03月12日

    :plus1: ,呵呵,楼主厉害呀,不过使用的工具 tumblr 挺不错的,我使用 fengche.co 来管理进度,多看这个看书软件真不错 (wifi 传书),有道笔记做个笔记的也挺好的,发现在地铁里面看书有时候效率会出奇的好,哈哈

  • Puma 源代码分析 - IO 处理 at 2015年03月12日

    :plus1: 收藏,后续细细品读一下,谢谢分享

  • 求 GitHub 优秀项目推荐 at 2015年03月11日

    @flowerwrong ,这个链接很给力, :plus1:

  • 动态方法和幽灵方法的简单 benchmark at 2015年03月10日

    我自己测了一下,有点超乎我的预计,呵呵,不过 Ruby 追求的不是性能

    class EntryNormal
      def e_0;end
      def e_1;end
      def e_2;end
      def e_3;end
      def e_4;end
    end
    
    class EntryNormal2
      def e_0(x);x;end
      def e_1(x);x;end
      def e_2(x);x;end
      def e_3(x);x;end
      def e_4(x);x;end
    end
    
    class Entry
      5.times do |i|
        define_method("e_#{i}"){}
      end
    end
    
    class Entry2
      def initialize(n)
        n.times do |i|
          Entry2.define_component("e_#{i}")
        end
      end
    
      def self.define_component(name)
        define_method(name) do |x|
          x
        end
      end
    end
    
    class Entry3
      def method_missing(method, arg)
        arg
      end
    end
    
    require 'benchmark/ips'
    
    Benchmark.ips do |x|
      x.report("normal method") do
        en = EntryNormal.new
        en.e_0
        en.e_1
        en.e_2
        en.e_3
        en.e_4
      end
    
      x.report("normal method args") do
        e = EntryNormal2.new
        e.e_0(1)
        e.e_1(2)
        e.e_2(3)
        e.e_3(4)
        e.e_4(5)
      end
    
      x.report("method_missing") do
        e = Entry3.new
        e.e_0(1)
        e.e_1(2)
        e.e_2(3)
        e.e_3(4)
        e.e_4(5)
      end
    
      x.report("dynamic method") do
        e = Entry.new
        e.e_0
        e.e_1
        e.e_2
        e.e_3
        e.e_4
      end
    
      x.report("dynamic method args") do
        e = Entry2.new(5)
        e.e_0(1)
        e.e_1(2)
        e.e_2(3)
        e.e_3(4)
        e.e_4(5)
      end
    
      x.compare!
    end
    

    Result:

    Calculating -------------------------------------
           normal method    64.900k i/100ms
      normal method args    63.045k i/100ms
          method_missing    57.231k i/100ms
          dynamic method    56.053k i/100ms
     dynamic method args     5.584k i/100ms
    -------------------------------------------------
           normal method      2.084M (±10.7%) i/s -     10.319M
      normal method args      1.801M (±11.1%) i/s -      8.889M
          method_missing      1.495M (±13.5%) i/s -      7.326M
          dynamic method      1.245M (±13.1%) i/s -      6.110M
     dynamic method args     57.401k (±13.6%) i/s -    284.784k
    
    Comparison:
           normal method:  2084278.1 i/s
      normal method args:  1801098.3 i/s - 1.16x slower
          method_missing:  1494748.3 i/s - 1.39x slower
          dynamic method:  1244953.5 i/s - 1.67x slower
     dynamic method args:    57401.2 i/s - 36.31x slower
    
    [Finished in 35.4s]
    
  • 中文互联网有没有类似 ROT13 这样的东西? at 2015年03月10日

    ❓ @jex 做这个主要的目的是什么呢?加密敏感词?

  • Linux 关不了机,每次都要按主机上的电源键 at 2015年03月10日

    😪 我这几天也正好遇到,ubuntu 单系统关不了机,卡在了 logo 页面,想来也是如上这些分析,回去查查电源管理问题, 😏

  • Ruby on Rails 个人视频教程 at 2015年03月10日

    :plus1:,支持你一个,若需要合作小伙伴可以加我一个

  • 上一页
  • 1
  • 2
  • 3
  • 4
  • 5
  • 下一页
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English