尝试呈现模式以更新任务,但是当使用 remote: true 和 link_to 时,它只请求 html 格式,我什至检查了也不接受 js 的请求 header 。
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
我不确定出了什么问题。我已经尝试在 link_to 中说明格式并在 Controller 中有一个 response_to 但这会呈现原始文本 html 而不是在我的 .js.haml 中执行 js
违规代码:
查看[.html.haml]:
= link_to 'Edit', edit_task_path(task), remote: true
Controller :
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 else 提交表单,并且一切正常。
最佳答案
根据 Controller 中的以下代码进行更改。
respond_to do |format|
format.html { render layout: 'YOUR LAYOUT' }
format.js
end
you can use template or text in place of layout.
关于ruby-on-rails - Rails link_to 与远程 : true not requesting JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45433770/