而无需刷新页面你如何提交轨3的形式? [英] How do you submit a rails 3 form without refreshing the page?

查看:74
本文介绍了而无需刷新页面你如何提交轨3的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了使用AJAX和放大器完成这件事; PHP的,但不是轨道3。

I've seen this done using ajax & php, but not rails 3.

我使用的尝试:

<%= form_for(:technician, :url => {:controller => 'pos', :action => 'create_ticket'}, :remote => true) do |f| %>  

但网页仍然刷新每次。我建立一个销售点的程序,所以我不想页面刷新。

but the page still refreshes each time. I'm building a point of sale program, so I don't want the page to refresh.

如何发送表单数据到控制器处理和存储在数据库中没有清凉?

How do I send the form data to the controller to process and store in the database without refreshing?

推荐答案

使用Rails 3,UJS,中添加远程属性足以改变一个请求,AJAX一个简单的事实的到来。

With Rails 3 and coming of the UJS, the simple fact of adding the remote attribute is sufficient to transform a request to AJAX.

不过,该请求被处理为AJAX,这意味着你的JavaScript库加载Rails的。

But, for the request is handled as AJAX, this implies you have the Rails javascript library loaded.

这意味着,你应该包括rails.js在你的头文件。

That means, you should include the rails.js file on your header.

在你layout.erb.html,你应该找到

In your layout.erb.html, you should find

<%= javascript_include_tag :defaults %>

而在你的公共/ JavaScript的目录,你会发现:

And in your public/javascripts directory, you should find :

application.js, controls.js, dragdrop.js, effects.js, prototype.js, rails.js

那么它应该工作。

Then it should work.

这篇关于而无需刷新页面你如何提交轨3的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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