尝试渲染一个模态来更新任务,但是当使用remote: true和link_to时,它只请求html格式,我什至检查了也不接受js的请求标头。
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
我不太确定出了什么问题。我尝试在 link_to 中说明格式并在控制器中使用 respond_to ,但这会呈现原始文本 html 而不是在我的 .js.haml 中执行 js
违规代码:
查看[.html.haml]:
= link_to 'Edit', edit_task_path(task), remote: true
控制器:
def edit
@task = Task.find(params[:id])
render :show_form
end
show_form.js.haml:
:plain
$('#modal1').modal('open');
$('#modal1').html("#{escape_javascript(render partial: 'create_task', locals: {task: @task})});
另外,我还包含了所有必需的库,我什至在代码中的其他位置使用了 remote: true 来提交表单,一切都正常。