阻止 Rails 重定向页面
我遇到了一些麻烦,我希望有人可以帮助我。我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对您的帖子的印象是您想要提交表单并在不离开页面的情况下显示结果。您想要做的事情需要使用 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.