折腾了一阵子,总算搞定了在rails console(包括irb)下中文的问题

我是通过rvm安装ruby的,所以需要用以下方式安装readline(一开始用brew install readline死活没用)

rvm pkg install readline
rvm remove
1.9.3
rvm install
1.9.3--with-readline-dir=$rvm_path/usr

OK

====================================

rails console作用真的很大,下面介绍如何直接模拟request,返回response,以及调用helper

> app.get '/posts/1'
> app.post('/foo', {"this" => "that", "items" => ["bar", "baz"]})
> app.put('/foo', {"this" => "that", "items" => ["bar", "baz"]}) > response = app.response > response.body #查看返回body
> response.cookies #查看cookie
> response.status
> response.headers
> app.session  #查看session
> app.session[:xx] = 1  #设置session
> app.flash  #查看flash
> app.flash[:info|:notice|:error]  #设置flash

调用helper
>> helper = ActionView::Base.new
>> helper.extend ApplicationHelper  #或者自己的其他helper module
>> helper.your_helper_method(args)

 

 

相关文章:

  • 2022-12-23
  • 2021-06-21
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
猜你喜欢
  • 2022-02-13
  • 2021-09-27
  • 2021-11-23
  • 2022-12-23
相关资源
相似解决方案