28
我想在我的Rails應用程序中使用一些Javascript。太少參數
我希望我的索引頁允許我編輯索引頁上的單個項目,然後在編輯時重新加載索引頁。
我index.html.erb頁的樣子:
<div id="index">
<%= render 'index' %>
</div>
在我index.js.erb的我:
$('#index').html("<%=j render 'index' %>");
,並在我的holders_controller:
def edit
holder = Holder.find(params[:id])
end
def update
@holder = Holder.find(params[:id])
if @holder.update_attributes(params[:holder])
format.html { redirect_to holders_path } #, flash[:success] = "holder updated")
## ^---Line 28 in error
format.js
else
render 'edit'
end
end
當我加載索引頁時,它很好。只要單擊編輯按鈕並提交表單時,我得到如下:
但是,如果我回去,並刷新索引頁,編輯內容被保存。我究竟做錯了什麼?
'responds_to do' – clyfe
對,謝謝。 :) – Matzi
@Matzi我不得不使用'responds_to do | format |'來使它工作。 –