我有“预订”模型和列:title
,permalink
,authorname
,description
:
before_save :change_permalink
before_update :change_permalink
private
def change_permalink
self.permalink = operation_with_title(title)
end
def operation_with_title(string)
mytitle = string.downcase!
mytitle.delete!(".,?!()@#\$&*^%-+=/[]{}<>`~''\"")
new_string = []
mytitle.each_char do |c|
if translit.key? c
new_string << translit[c]
else
new_string << c
end
end
new_string.to_s
end
def translit
{
"а" => "a", "б" => "b", "в" => "v",
"г" => "g", "д" => "d", "е" => "e",
"ё" => "jo", "ж" => "zh", "з" => "z",
"и" => "i", "й" => "ij", "к" => "k",
"л" => "l", "м" => "m", "н" => "n",
"о" => "o", "п" => "p", "р" => "r",
"с" => "s", "т" => "t", "у" => "u",
"ф" => "f", "х" => "h", "ц" => "c",
"ч" => "ch", "ш" => "sh", "щ" => "xh",
"ь" => "", "ы" => "y", "ъ" => "",
"э" => "je", "ю" => "ju", "я" => "ja",
" " => "_"
}
end
我想访问title
,对其进行更改并添加到permalink
。
但我不知道如何在我的方法中访问title
。
答案 0 :(得分:0)
title
应与self.title
你能告诉我们你的尝试以及它给你的错误吗?