• 求一点引导 at March 31, 2015

    個人發展軌跡

    1. rails 寫過 blog 了沒?沒有就去寫一個吧
    2. ruby 學了沒?從基礎語法到員編程,可以試着自己寫 gem 來練習。
    3. 貢獻源代碼來提高自己,閱讀源代碼不如貢獻,當然先閱讀,再貢獻
    4. 以後走前端還是後臺,先不說全棧吧?前端就去學js css html,最近 js 大火,bootstrap 只是一個 css 框架。後臺建議去學算法,套接字,網絡協議,unix 網絡編程等等。

    書籍補充 (不要問我爲什麼是 dangdang)

    理解 Unix 进程 TCP Sockets 编程 UNIX 环境高级编程 鸟哥的 Linux 私房菜 基础学习篇 (第三版) Ruby 基础教程(第 4 版) Ruby 元编程

  • # rename a rails 4.1.x application with three files
    
    # config/application.rb
    require File.expand_path('../boot', __FILE__)
    require 'rails/all'
    Bundler.require(*Rails.groups)
    module YourApplicationName # <-- rename it here
       class Application < Rails::Application
       end
    end
    
    # config/initializers/session_store.rb
    Rails.application.config.session_store :cookie_store, key: '_your_application_name_session' # <-- rename the key
    
    # database.yml
    # database name
    
  • 首先,你的问题是挺有深度的。但是我觉得不是你现在的关注点。你了解了这个问题对你现在有帮助吗? 这种问题我不会,不知道论坛有多少人清楚。 而且这种东西有技术趋势和各方面的因素在里面,比如架构师个人的技术爱好,擅长的东西不同,那么选择也就不同。 综上:just do it

  • #2 楼 @QueXuQ

    # seesion_store.rb
    Rails.application.config.session_store :cookie_store, key: '_key_session'
    
    # in application.rb, do not do this
        config.middleware.delete ActionDispatch::Cookies
        config.middleware.delete ActionDispatch::Session::CookieStore
    
  • 这个不需要额外设置。 写一个前置 filter,类似

    def current_user
      if session[:user_id]
        @current_user = User.find_by id: session[:user_id]
      else
        @current_user = set_current_user
      end
    end
    
      def http_auth_content
        return @http_auth_token if defined? @http_auth_token
        @http_auth_token = begin
          if params[:auth_token].present?
            params[:auth_token]
          elsif request.headers['Authorization'].present?
            request.headers['Authorization'].split(' ').last
          else
            # fail NoAuthTokenError
            nil
          end
        end
      end
    
    def set_current_user
      @auth_token = http_auth_content
      unless @auth_token.blank?
        @current_user ||= User.where(auth_token: @auth_token).first
      end
    end
    
  • 微信支付 Gem at March 27, 2015

    #12 楼 @robot_zhang 不是的,是需要利用 11 楼的 hash 再加上 key,然后 sort~>md5

    @js_noncestr = SecureRandom.uuid.tr('-', '')
    @js_timestamp = Time.now.getutc.to_i.to_s
    @app_id = app_id
    @package = "prepay_id=#{@ra[:r]['prepay_id']}"
    
    params_pre_pay_js = {
        appId: @app_id,
        nonceStr: @js_noncestr,
        package: @package,
        timeStamp: @js_timestamp,
        signType: 'MD5'
    }
    @js_pay_sign =     WxPay::Sign.generate(params_pre_pay_js)
    
  • 微信支付 Gem at March 27, 2015

    #11 楼 @jasl 谢谢你的 wx_pay gem,让我省了不少时间。代码也很漂亮。

  • 微信支付 Gem at March 26, 2015

    #10 楼 @robot_zhang package 拼了,是签名时大小写不对。比如 appId , 小写就不行。

    #11 楼 @jasl :plus1: 谢谢,大小写都必须一样

  • 微信支付 Gem at March 26, 2015

    #8 楼 @jasl 我遇到了一个问题,不知道你有没有遇到过。我测试支付的时候显示 商户签名失败 , 网上的大多是没有拿到 prepay_id ,但是我这边是拿到了的。问题出在 js 那里:

    function onBridgeReady(){
       WeixinJSBridge.invoke(
           'getBrandWCPayRequest', {
               "appId" : "wx2421b1c4370ec43b",     //公众号名称,由商户传入     
               "timeStamp":" 1395712654",         //时间戳,自1970年以来的秒数     
               "nonceStr" : "e61463f8efa94090b1f366cccfbbb444", //随机串     
               "package" : "prepay_id=u802345jgfjsdfgsdg888",     
               "signType" : "MD5",         //微信签名方式:     
               "paySign" : "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 
           },
           function(res){     
               if(res.err_msg == "get_brand_wcpay_request:ok" ) {}     // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回    ok,但并不保证它绝对可靠。 
           }
       ); 
    }
    if (typeof WeixinJSBridge == "undefined"){
       if( document.addEventListener ){
           document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
       }else if (document.attachEvent){
           document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
           document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
       }
    }else{
       onBridgeReady();
    } 
    

    paySign 我不知道应该是填写预下单的时候发送的 sign,还是返回的数据中的 sign,两个 sign 不一样。我还试过自己生成一个新的。但都是报 商户签名失败

  • #5 楼 @Martin91 nan474947

  • ! 群人数已达上限 😪

  • #3 楼 @yan32768 如果是新手,你选错语言了。ruby 的数据挖掘资料极少。当然你也可以语言混用。 自然语言处理 list

  • Flask 代码执行效率问题 at March 24, 2015

    😪 你还是去 py 的国内邮件列表或者 v2ex 吧,这里的人大多玩 ruby.

  • #18 楼 @hooopo

    Concern 需要 ActiveSupport::Concern 才能玩的转,而 Service Object 就是普通 Object。

    ActiveSupport::Concern 不是必要的,它其实只是一种简写。

    官方文档 activesuport concern

    # metaprogramming ruby 一书中的写法
    module M
      def self.included(base)
        base.extend ClassMethods
        base.class_eval do
          scope :disabled, -> { where(disabled: true) }
        end
      end
    
      module ClassMethods
        ...
      end
    end
    
    # rails的简写
    require 'active_support/concern'
    
    module M
      extend ActiveSupport::Concern
    
      included do
        scope :disabled, -> { where(disabled: true) }
      end
    
      class_methods do
        ...
      end
    end
    
  • #4 楼 @wxliuzifan 这不是说你密码错误嘛

  • #14 楼 @Rei #13 楼 @lyfi2003 OK, 明白了,thx.

  • @Rei railtie line 这里没看懂。加 Railtie 类继承 rails 的 railtie 的目的是什么?

  • 与 rails4 引入的 concern 相比,好处在哪里呢? 我了解到 concern 只是抽出为了可以复用的类。然后 mixin 进需要他的地方。我觉得严格来说不是加入了层的概念。

  • :plus1:

  • [广州] RubyGZ slack 群组 at March 21, 2015

    #4 楼 @justin 过期了,换一个

  • DHH 说------我从来不用 windows

  • 英文书记推荐得不错,Assets Pipeline 我也是很醉的,同 lz 一样买主题。 所以新项目一律前后端分离,rails 只做 api

    rm -rf app/views
    rm -rf app/assets
    rm -rf verdor
    
    # remove gem in Gemfile, 只剩下了
    gem 'rails', '4.2.0'
    gem 'mysql2'
    
    # application.rb
    # require 'rails/all'
    # gem which rails/all
    require 'active_record/railtie'
    require 'action_controller/railtie'
    # require 'action_view/railtie'
    require 'action_mailer/railtie'
    # require 'active_job/railtie'
    require 'rails/test_unit/railtie'
    # require 'sprockets/railtie'
    
    # remove none useful middleware
    config.middleware.delete ActionDispatch::Flash
    config.middleware.delete Rack::Sendfile
    config.middleware.delete ActionDispatch::Cookies
    config.middleware.delete ActionDispatch::Session::CookieStore
    
        config.generators do |g|
          g.orm             :active_record
          g.template_engine :erb
          # g.test_framework  :test_unit, fixture: false
          # g.test_framework  nil
          g.stylesheets     false
          g.javascripts     false
          g.jbuilder        false
          g.helper          false
        end
    
  • [广州] 招聘 Ruby 工程师 at March 20, 2015

    炮哥 =_=

  • 37 Metaprogramming Ruby 第二版,谢谢

  • articles/1

    [{id: 1}, {}]

    articles/1/comments

    [{id: 1, comments: [{}]}, {}]

  • 关于用户权限的问题 at March 19, 2015
  • | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 3424 | 2635 | 38 | 321 | 8 | 6 | | Helpers | 543 | 535 | 0 | 6 | 0 | 87 | | Models | 351 | 257 | 30 | 8 | 0 | 30 | | Mailers | 0 | 0 | 0 | 0 | 0 | 0 | | Javascripts | 13629 | 8412 | 0 | 711 | 0 | 9 |

  • 建议都不,能运行就行了!!!

  • [广州] 招聘 Ruby 工程师 at March 18, 2015

    顶顶