开发者

How do you submit a rails 3 form without refreshing the page?

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

I've tried using:

<%= 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 f开发者_C百科orm data to the controller to process and store in the database without refreshing?


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

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

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

In your layout.erb.html, you should find

<%= javascript_include_tag :defaults %>

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.


If in rails, you should make some file also in .js format and render it after save in controller. For example render create.js after save in create controller. In file create.js.erb, you should render back what you want to view after save that form

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜