Sas*_*sha 0 ruby-on-rails undefined
我正在关注迈克尔·哈特尔的书,并一直在做一个我似乎无法弄清楚的可选练习。
我有一个帮手,叫
module MicropostsHelper
def wrap(content)
sanitize(raw(content.split.map{ |s| wrap_long_string(s) }.join(' ')))
end
private
def wrap_long_string(text, max_width = 30)
zero_width_space = "​"
regex = /.{1,#{max_width}}/
(text.length < max_width) ? text :
text.scan(regex).join(zero_width_space)
end
end
Run Code Online (Sandbox Code Playgroud)
我正在尝试包装应该是用户输入中的字符串的内容。在我的控制器中,
def create
flash[:notice] = "[][] is...", params[:micropost][:content]
cleaned = wrap(params[:micropost][:content])
@micropost = current_user.microposts.build(cleaned)
...
Run Code Online (Sandbox Code Playgroud)
但是我不断收到未定义的方法“原始”。有人可以解释为什么吗?
有没有显示方法示例的 api?
您可以在 html 视图中使用string.html_safe或r 'string'
| 归档时间: |
|
| 查看次数: |
1813 次 |
| 最近记录: |