我試圖通過單擊Link_to
呈現boxes_list
。不知道爲什麼它不工作。Link_to不從自定義控制器動作呈現部分
# Routes.rb
resources :modifications do
collection do
get 'refresh'
end
end
# ModificationsController
def refresh
respond_to do |format|
format.js {}
end
end
# link in /views/modifications/_boxes_list.html.erb that should refresh boxes_list
<%= link_to "refresh", refresh_modifications_path(@modification), remote: true, method: :refresh %>
# JS responce in /views/modifications/refresh.js.erb
$('#boxes_count').html("<%= escape_javascript(render(:partial => 'boxes_list')).html_safe %>");
在服務器控制檯中,當按此鏈接時,我什麼都看不到。鏈接在正常顯示操作下的修改顯示頁面上。 Rails 4!
我嘗試了,但現在我有這樣的:'已完成406不可接受在3ms ActionController :: UnknownFormat(ActionController :: UnknownFormat):app/controllers/modifications_controller.rb:18:in'refresh'' – DanielsV
您可以從'/ views/modifications/refresh.js.erb'文件中發表評論,並寫下'alert(Hello)'。這會測試你的代碼,它會通過'ajax'調用進行'刷新'。試過讓我知道 –
,但是與未知格式相同的問題。警報不要射擊! – DanielsV