rails console下中文输入的问题以及直接调用helper/request/response

折腾了一阵子,总算搞定了在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)

 

 
posted @ 2012-07-28 14:19  我的白日梦  阅读(720)  评论(0)    收藏  举报