Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
arnkorty
@fumesy
高级会员
第 309 位会员 / 2011-11-29

2 篇帖子 / 42 条回帖
1 关注者
1 正在关注
16 收藏
未设置 GitHub 信息。
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • render 时 template 和 partial 有什么区别么? at 2016年09月09日
    <%= render partial: "home/show" %>     <!--  查找 home/_show.html.erb -->
    <%= render template: "home/show" %> <!--  查找 home/show.html.erb -->
    
  • 建议 Ruby-China 把 “求职” 全部替换为 “找工作” at 2015年09月30日

    :plus1:

  • 使用 message_bus 过程中,如新建订单获取到一条通知,居然会提示多次,问题出现在 message_bus.js 的回调函数调用了多次,如何解决? at 2015年09月29日

    你的 server 使用 webrick?

  • 使用 message_bus 过程中,如新建订单获取到一条通知,居然会提示多次,问题出现在 message_bus.js 的回调函数调用了多次,如何解决? at 2015年09月29日

    贴出调用的代码和 log

  • Rails Enum 的疑问 at 2015年09月22日

    使用 string,symbol,int 赋值都是可以的

    Conversation.create status: :active
    Conversation.create status: "active"
    Conversation.create status: 0
    Conversation.create status: Conversation.statuses[:active] 
    # 这三种写法都是有效的,其中 Conversation.statuses[:active] 等效 0
    

    https://github.com/rails/rails/blob/08576b94ad4f19dfc368619d7751e211d23dcad8/activerecord/lib/active_record/enum.rb#L82

  • Rails 中有没有作业调度的框架? at 2015年09月21日

    https://github.com/chanks/que

  • Ruby 数组只是一种方法? at 2015年09月19日

    [] 的本身是一个方法名。http://ruby-doc.org/core-2.2.3/Array.html#method-i-5B-5D 访问的时候,会 check 这个下标是否在这个数组里面。

    定义一个[]方法。

    class A
      def [](index)
        "this is a [] method"
      end
    end
    A.new[1]  #=> "this is a [] method"
    A.new["index"]  #=> "this is a [] method"
    
  • Rails 里微信公众号相关开发能本地测试吗? at 2015年09月18日

    localtunnel

  • 跪求各位大神关于 Rails 启动的问题 at 2015年09月17日

    这个可以从 log 看出问题。

    /usr/local/lib/ruby/gems/2.1.0/gems/execjs-2.6.0/lib/execjs/runtimes.rb:48:in `autodetect': Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
    

    没有安装 JavaScript runtime, 可在这里 https://github.com/rails/execjs 挑一个,建议安装 nodejs

  • 通过 ActiveJob 获取 real job id (Sidekiq) at 2015年09月16日

    #1 楼 @kingwkb ActiveJob 功能虽然功能有限,但更易用。比如:

    class ActiveJobPlus < ActiveJob::Base
       queue_as  :plus  
       #before_enqueue do |job|
       #end   
       #after_enqueue do |job|
       #end
       #before_enqueue do |job|
       #end
       #before_perform do |job|
       #end
      #after_perform do |job|
      #end
    end
    
    class YourJob < ActiveJobPlus
        def perform(args)
        end
    end
    

    这样可以对共通部分进行处理。

  • 程序启动时怎么指定 development,production,test 之外的数据库?RAILS_ENV 的参数要写什么? at 2015年09月16日

    rails c -e data_99 rails s -e data_99 多个数据库,建议使用 establish_connection

  • Simple Rails history pattern (ActiveRecord) at 2015年09月15日

    之前在公司里,保存历史数据都是使用触发器来实现。

  • 关于连接其它数据库的配置 at 2015年09月13日

    #4 楼 @hxh1246996371 🆒 不过在 ActiveRecord::Base 中有一些 configurations, connection_config 等方法,如定config 方法容易引起理解歧义,建议定义类似 kexin_config 这样感觉好些。

  • 关于连接其它数据库的配置 at 2015年09月13日
    # app/models/kexin_db_base.rb
    class KexinDbBase < ActiveRecord::Base
        self.abstract_class = true
       ActiveRecord::Base.establish_connection Rails.application.config.kexin_db
    end
    
    # app/models/apm_sell_mem.rb
    class ApmSellMem < KexinDbBase
       self.table_name = "mems"
       {
          :my_age=> :age,
          :my_name=> :name
       }.each do |k,v|
         alias_attribute k, v
      end
      .....
    end
    
  • go_to_state :payment, if: ->(order) { order.payment_required? } 其中的 if: -> 是什么意思? at 2015年09月12日

    #2 楼 @viciousstar 是的,只要带有 : 都是一个 Symbol

  • go_to_state :payment, if: ->(order) { order.payment_required? } 其中的 if: -> 是什么意思? at 2015年09月12日

    -> 是定义一个 lambda, 功能和 lambda{} 一致。 if: ->(order) { order.payment_required? } 是一个 hash 参数。具体这个参数有什么作用,可以在 https://github.com/spree/spree/blob/master/core/app/models/spree/order/checkout.rb#L128 查到

  • 在 view 中,render 中的 locals 是怎么传递过去的?我想判断 partial 中是否有 locals,要怎做呢? at 2015年09月12日

    if local_assigns[:custom_name] ... 或 if defined?(:custom_name) ...

  • 如何解决 Grape API 的 url 在少了一个 / 的情况下居然还能工作的问题 at 2015年09月12日
    # routes.rb
    mount Api::Dispatch => '/'
    
    # api/dispath.rb
    prefix '/api'
    
  • passenger 的正确启动方式?怎样才能指向 current 版本?capinstrano 自动启动的方法? at 2015年09月10日

    #8 楼 @chairy11 是的,在 nginx 中添加 passenger 的配置就可以了,你可以检查 nginx 的配置是否有问题 sudo nginx -t -c /etc/nginx/nginx.conf # or your config file path

  • passenger 的正确启动方式?怎样才能指向 current 版本?capinstrano 自动启动的方法? at 2015年09月10日

    #5 楼 @chairy11 执行 passenger-config --root passenger-config --ruby-command 把结果写入 passenger_root passenger_ruby ,然后重启 nginx,看是否正常。

  • passenger 的正确启动方式?怎样才能指向 current 版本?capinstrano 自动启动的方法? at 2015年09月10日

    #2 楼 @chairy11 有可能是你的 passenger_ruby配置有问题,如是使用 rvm 还需要做一些改变。 https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_ruby 另外 rvmsudo passenger start -e production -p 80 --user="root" 和 nginx 的 passenger 启动是不同的,一个是standalone,一个是作为 nginx 的插件的形式。

  • passenger 的正确启动方式?怎样才能指向 current 版本?capinstrano 自动启动的方法? at 2015年09月09日

    添加passenger_app_root /app/www/my_project/current https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_app_root

  • Grape 的 JSON 参数验证,以及 nested params 问题 at 2015年08月30日

    grape 使用好像没有发现类似的问题。你先在 log 中,看看 post 后,grape 解析后的参数。

  • 特复杂的页面怎么解析 at 2015年08月29日

    使用 inner_html 方法来获取code tag 内容后处理。

    doc.at("#__cnt_0_19").inner_html
    
  • 特复杂的页面怎么解析 at 2015年08月29日

    可以看出 #box-coolsite 在 <code id="__cnt_0_19" ... 内,并被注释了,你可以先获取<code 内的 inner_html,然后对里面的数据进行处理。 hao123 源码

  • [已经解决,thx] ActiveRecord::Base after_find 的问题 ! at 2015年08月29日

    這個地方應該使用 serialize

    class Role < ActiveRecord::Base
       serialize :rule, JSON
    end
    
  • UPYUN 云存储免费了! at 2015年08月28日

    🍻 ,得看流量

  • 如何将一维数组转换成哈希 at 2015年08月28日
    Hash[1,2,3,4]   #=> {1 => 2, 3 => 4 }
    
  • zsh_stats 查看你命令使用频率 at 2015年07月30日
     1  2554  25.5426%   git
     2  1480  14.8015%   cd
     3  1033  10.331%    vim
     4  857   8.57086%   ls
     5  421   4.21042%   ssh
     6  355   3.55036%   bundle
     7  330   3.30033%   rails
     8  329   3.29033%   rvm
     9  257   2.57026%   rm
    10  250   2.50025%   brew
    11  160   1.60016%   rake
    12  135   1.35014%   cap
    13  114   1.14011%   mina
    14  114   1.14011%   gem
    15  80    0.80008%   ruby
    16  74    0.740074%  more
    17  64    0.640064%  npm
    18  61    0.610061%  ping
    19  56    0.560056%  cp
    20  54    0.540054%  ps
    
  • 1
  • 2
  • 下一页
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English