0
感謝您的時間!調用控制器的動作,但不要跳到ERB視圖
我得到航線routes.rb
:
get "loadreport/test"
post "loadreport/update"
在loadreport
控制器test
函數是一個空函數:
def test
end
的test.html.erb包含:
<form action="/loadreport/update?method=post" class="button_to" method="post">
<div>
<input type="submit" value="Update" />
<textarea cols="30" id="post_body" name="comments" rows="5" maxlength=200>
</textarea>
</div>
</form>
update
函數wi LL更新數據庫:
def update
some_database.update(params[:comments])
end
現在,當我點擊test.html.erb
的Update button
,它會調用/loadreport/update
,並跳轉到update.html.erb
。由於update.html.erb
不存在,服務器就會給我像錯誤:Template is missing ... blah ...
我想實現的是:當我點擊test.html.erb
的Update button
,它可以簡單的叫/loadreport/update
來更新數據庫,然後彈出一個消息框其中說「更新成功!」,而不是跳轉到另一頁。
如何更改我的代碼以實現該目的?任何人都可以給我一些想法或關於這個話題的一些鏈接。謝謝!
感謝您的回答。我嘗試了Ajax,發現它非常強大。我已經用Ajax完成了。 – mCY