嗯,我对sinatra或RoR很新,我正在构建一个包含一些语言的表格用于翻译目的。
我使用以下格式保存数据(language => key => translation)
当发送用户引入的数据(翻译)时,保存在中间的+
。例如
en=>slogan=>we+save+energy
问题:如何避免此+
?
形式:
<form action="" method="POST" >
<table >
<tr>
<th>ID</th>
<th>keys</th>
<th>German</th>
<th>English</th>
<th>French</th>
<
</tr>
<% @DE["de"].each do |key,value| %>
<tr>
<td><%= i+= 1 %></td>
<td id= "key<%= i %>"><%= key %></td>
<td><textarea id="de<%= i %>" readonly ><%= value %></textarea></td>
<td><textarea id="en<%= i %>" name="en<%= i %>"><%= @valuesEN[i] %></textarea></td>
<td><textarea id="fr<%= i %>" name="fr<%= i %>"><%= @valuesFR[i] %></textarea></td>
</tr>
<% end %>
</table>
</form>
这是JQuery部分:
$('textarea').change(function(e){
var pointer = $(this);
var color = pointer.css("background-color");
if (color == 'rgb(250, 187, 0)'){
var id = pointer.attr("id");
var getNumberFromId = id.substr(2,3);
var getLanguage = id.substr(0,2);
var getKey = $("#key"+getNumberFromId).html();
e.stopPropagation();
pointer.css('background-color','#8Fbc8F'); // Change field to green
toServer(pointer,getKey, getLanguage);
}
});
function toServer(pointer, key, language) {
$.ajax({
type: 'POST',
url: 'translator/translate/'+language+'/'+key,
data: {"data":pointer.serialize()},
success: function(data){
}
});
}
接收服务器中的数据:
post '/translator/:lang/:key' do
language = params[:lang]
key = params[:key]
translation = params[:data]
File.open('translation_file.txt', 'a') do |f|
f.print language
f.print "=>"
f.print key
f.print "=>"
f.puts translation
end
end