我试图通过单击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