address
Ajaxを使用してテキストエリアを更新しようとしています。
アプリケーション.js
$("#invoice_project_id").change(function() {
$.ajax({
url: '/invoices/get_recipient',
data: 'project_id=' + this.value,
dataType: 'script'
})
});
請求書_controller.rb
def get_recipient
project = Project.find(params[:project_id])
@recipient = project.person.address
end
get_recipient.js.erb
$('#invoice_recipient').val("<%= @recipient %>");
どうやら、おそらくaddress
.
たとえば、別の属性を使用するfirst_name
と、全体がかなりうまく機能します。
@recipient = project.person.first_name
どうすればこれをaddress
同様に動作させることができますか?
アドレス内の改行は何らかの方法でエスケープする必要があると思いますが、まだその方法を見つけていません。
助けてくれてありがとう!