2013-02-05 32 views
0

在我index.html.erb我有一個按鈕,如:充分利用AJAX回調Rails中

<%= button_to 'Test', question_path, :remote => true, :class => "btn btn-primary btn-large" %> 

這會觸發一個方法在我的控制器,它要求一個簡單的字符串值的服務器,並且該方法成功獲得答案。這已由puts question.gets驗證。

我想將該答案傳遞迴index.html.erb並在<div>中顯示。

回答

1

創建一個app/views/questions/show.js.erb並在此處添加您需要的js代碼。

# controller 
def show 
    @question = ... # fetch question 
end 

# show.js.erb 
$('#div_id').text('<%= escape_javascript @question.gets %>');