Notes posted by azhao

RSS feed
November 10, 2015
0 thanks

instead of memoize

See this for deprecated github.com/rails/rails/commit/36253916b0b788d6ded56669d37c96ed05c92c5c

use

def something
  return @_var if defined? @_var
  # more code
end
June 3, 2015 - (v4.0.2 - v4.2.1)
0 thanks

render with variables

perient view

Code example

<%= render 'time_select', locals: { select_name: 'from_tiem'}%>

render view

Code example

<%= locals[:select_name] %>

not:

Code example

<%= local_assigns[:select_name] %> 
April 2, 2013 - (v1_9_3_392)
0 thanks

output GBK

‘I am 中国人’.encode(‘gbk’,‘utf-8’)

April 2, 2013
0 thanks

you need kconv

require ‘kconv’

then

“中国人民很行”.toutf8

May 10, 2012
0 thanks

block only and except

Code

class Journal < ActionController::Base
  # Require authentication for edit and delete.
  before_filter :authorize, :only => [:edit, :delete]

  # Passing options to a filter with a block.
  around_filter(:except => :index) do |controller, action_block|
    results = Profiler.run(&action_block)
    controller.response.sub! "</body>", "#{results}</body>"
  end

  private
    def authorize
      # Redirect to login unless authenticated.
    end
end