阻止 Rails 重定向页面

发布于 2024-10-17 09:06:39 字数 557 浏览 4 评论 0原文

我遇到了一些麻烦,我希望有人可以帮助我。我有一个 erb 文件,其中有一个带有按钮的表单。当您单击该按钮时,它会将页面重定向到其他地方并显示我告诉它指向的 erb 文件。这很棒,但我真的很想将定向 erb 文件的内容填充到表单下方的 div 中。我的观点看起来像这样。

<div id="formentry">
  <%= form_for @time, :url => {:action => 'list'}, :remote => true, :update => 'results' do |f|%>
  <%= select :time, :period, TimeSelectModel::TIMEVALUES %>
  <%= f.submit "Submit" %>
<% end %>
</div>

<div id="results"></div>

从我在网上读到的内容来看,这似乎是您应该在 Rails3 中执行此操作的方法,但我没有发现它有效。 (参见:页面完全重定向)我做错了什么?谢谢。

I'm having some trouble and I hope someone can help me. I have an erb file with a form in it that has a button. When you click the button it redirects the page elsewhere and shows the erb file that I told it to point to. This is great except I'd really like to stuff the content of that directed-to erb file into a div that is sitting below my form. My view looks something like this.

<div id="formentry">
  <%= form_for @time, :url => {:action => 'list'}, :remote => true, :update => 'results' do |f|%>
  <%= select :time, :period, TimeSelectModel::TIMEVALUES %>
  <%= f.submit "Submit" %>
<% end %>
</div>

<div id="results"></div>

From what I've read online this seems like the approach you're supposed to take to do this in Rails3 but I'm not finding that it's working. (see: the page is completely redirecting) What am I doing wrong? Thanks.

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

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

发布评论

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

评论(1

少跟Wǒ拽 2024-10-24 09:06:39

我对您的帖子的印象是您想要提交表单并在不离开页面的情况下显示结果。您想要做的事情需要使用 javascript/ajax。

查看railscast 205 了解如何执行此操作的示例。

My impression from your post is that you want to submit a form and show the results without leaving the page. What you are looking to do requires use of javascript/ajax.

Checkout railscast 205 for an example of how to do this.

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