• 使用 Elixir 的中国公司 at 2017年1月23日

    @tony612 如果能把公司按城市区分那就更好了 能remote的公司还是比较少的

  • 我们用Actioncable实现了类似于Whatsapp类的聊天功能,不是非常的难。人不多的话没什么问题。scale的话也没什么问题,但如果人多的话我不会选择用Actioncable,太吃资源

  • 关于 Rails 的异常处理 at 2017年1月22日

    问题1

    There is no need to explicitly check whether the id exists or not. If you setup the routes correctly, then it would never have passed the routes if the required key does not exist.

    # routes.rb
    
    # products GET /products/:id(.:format) products#show
    resources :products
    

    In terms of exception rescuing on the controller level, like @huacnlee have said, you don't need to handle ActiveRecord::RecordNotFound as Rails has already handled it for you (rendering / returning 404), and you don't need to apply rescue_from in ApplicationController. If however you need to handle it differently in any particular actions, you can always rescue it per action.

    class ProductsController < ApplicationController
      def show
        @product = Product.find(params[:id])
      rescue ActiveRecord::RecordNotFound
        redirect_to :root, flash: { error: "产品不存在" }
      end
    end
    

    问题2

    You can rescue exceptions in model, just like any of the ruby classes and methods. However, general practices is, you'll only ever need to rescue exceptions if you don't know whether it is going to raise exceptions or not (这不是废话嘛..), eg: user inputs, external sources, api responses, and even then it should be handled on a higher level, eg: controllers, service objects, form objects and validators etc.

    Issues like you've described, (NoMethodError) should have never made to production code base with unit testings. Thats why it is essential to have unit testing on each of the methods in your model.

  • 这是因为actionmailer的设计理念。因为ActionMailer的父类是一个Controller,而Controller理论上只应该应对一个action。ActionMailer所以要防止你写这样的代码

    user_mailer = UserMailer.new
    user_mailer.foo
    user_mailer.bar
    
  • <%= submit_tag "返回", type: :button, onclick: "history.back()" %>
    
  • 选择是双向的 公司压低工资那就不要去 员工要太多工资那就不要请

  • 直接在routes里可以实现 http://guides.rubyonrails.org/routing.html#request-based-constraints

    namespace :ht do
      constraints subdomain: 'ht' do
        # backend resources
      end
    end
    
    namespace :qt do
      constraints subdomain: 'qt' do
        # frontend resources
      end
    end
    
  • lz在澳洲哪个公司就职?