【问题标题】:Rails 3.2.8 Remote Form Not WorkingRails 3.2.8 远程表单不工作
【发布时间】:2012-10-26 23:19:23
【问题描述】:

我有这个表单,它没有绑定到任何模型,我想 ajaxify。我试图弄清楚如何让它通过 ajax 提交,但我一定做错了,因为它不起作用(它只是做一个常规的 POST)。

我可以确认表单标记使用“远程”属性呈现,但是表单的任何地方都没有添加 js。我还添加了 :confirm 只是为了看看它是否也能正常工作。它没有。

jquery 和 jquery_ujs 都加载到页面上。

  %form{ :action => "/newsletter", :confirm => "Are you sure?", :remote => true, :method => "post", :id => "newsletterForm"}
    %p
      = label_tag(:q, "Subscribe to our newsletter:")
    %p
      = text_field_tag(:q, nil, :placeholder => "Your email address")
      = button_to("Subscribe", :remote => true)

【问题讨论】:

    标签: ruby-on-rails-3


    【解决方案1】:

    我刚刚写了这个,用一个表单做类似的事情:

      = form_tag('/signup', :method => "get", :remote => true, :id=> 'signup-form') do
        %label{:id => 'signup-label', :for=> 'signup-box'}
          Enter your email address
        = text_field_tag "signup-box", params[:signup], :class => 'text', :required => true, :id => 'signup-box'
        = submit_tag "Sign Up", :id => 'signup'
    

    控制器:

    class SignupController < ApplicationController
      def index
        puts "***************************************************"
        puts "email sign up"
        puts "***************************************************"
        render :nothing => true
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-28
      • 1970-01-01
      • 2013-09-15
      • 2021-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多