提交表格而无需更换带有涡轮的铁轨中的URL

发布于 2025-02-05 01:58:34 字数 271 浏览 2 评论 0原文

我有一条轨道表格,

= form_with url: submit_path, multipart: true, data: { turbo_frame: 'document_table_content' } do |f|
Form-row
  = f.submit t('.submit'), class: 'Button'

当我提交表格上的URL更改为submis_path时,我想将其成功提交,我想保持URL相同,这是可能的吗?

I have a rails form that I successfully submit with turbo

= form_with url: submit_path, multipart: true, data: { turbo_frame: 'document_table_content' } do |f|
Form-row
  = f.submit t('.submit'), class: 'Button'

When I submit the form the url changes to submit_path, I want to keep the url the same, is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似狗非友 2025-02-12 01:58:34

当然可以。 turbo表单提交仅接受重定向turbo_stream在响应中。如果您想留在当前页面上,并且您确实不想在提交后执行任何更改,则在您的控制器中呈现这样的turbo_stream:

def save_object
  object.update! params
  render turbo_stream: turbo_stream.remove('dummy-uniq-dom-id')
end

但是,您可能需要使用以下代码来更新同一页面的部分:

render turbo_stream: turbo_stream.replace('id-of-dom-element',
  partial: "path/to/render", locals: {if: 'any'}
)

注意该turbo_stream当前有7个操作:在此处阅读

Of course you can. Turbo form submission only accepts redirect or turbo_stream in response. If you want to stay on current page and you really don't want to perform any changes in it after submission, in your controller render a turbo_stream like this:

def save_object
  object.update! params
  render turbo_stream: turbo_stream.remove('dummy-uniq-dom-id')
end

However, you may want to update portion of the same page using following code:

render turbo_stream: turbo_stream.replace('id-of-dom-element',
  partial: "path/to/render", locals: {if: 'any'}
)

Note that turbo_stream has currently 7 actions: Read here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文