Rails link_to with remote: true 不请求 JS [英] Rails link_to with remote: true not requesting JS

查看:49
本文介绍了Rails link_to with remote: true 不请求 JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试渲染一个模态来更新任务,但是当使用 remote: true 和 link_to 时,它只请求 html 格式,我什至检查了也不接受 js 的请求标头.

Trying to render a modal to update a task but when using remote: true with link_to it just requests html format, I've even checked the request headers which also do not accept js.

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8

我不太确定出了什么问题.我试过在 link_to 中说明格式并在控制器中有一个 response_to 但这会呈现原始文本 html 而不是在我的 .js.haml 中执行 js

I'm not really sure what's wrong. I've tried stating the format in the link_to and having a respond_to in the controller but that renders a raw text html rather than executing the js in my .js.haml

违规代码:

查看[.html.haml]:

View [.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:

show_form.js.haml:

:plain
  $('#modal1').modal('open');
  $('#modal1').html("#{escape_javascript(render partial: 'create_task', locals: {task: @task})});

此外,我还包含了所有必需的库,我什至在代码中使用 remote: true else 提交表单,并且一切正常.

Also I have all the required libaries included, I even use remote: true else where in the code to submit forms and it all works fine.

推荐答案

在清单文件中写入以下内容 (application.js)

Write the below in your manifest file (application.js)

//= require jquery
//= require jquery_ujs

这篇关于Rails link_to with remote: true 不请求 JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆