开发者

Why am I getting html ajax response instead of javascript ? (ruby on rails)

Hi I'm 开发者_运维知识库pretty knew to Ruby on rails, perhaps it's some easy thing I didn't get in the book but I am trying to get an ajax js response and I keep getting html instead.

My views is the following new.html.erb:

<% form_for(resource, :as => resource_name,   
            :remote => true, :url => registration_path(resource_name)) do |f| %>
    <%= f.label :name %><br />
    <%= f.text_field :name %>

  <%= f.submit "Sign Up" %>
<% end %>

My controller : registrations_controller.rb

  # POST /resource
  def create
    build_resource

    if resource.save
      if resource.active?
        set_flash_message :notice, :signed_up
        sign_in_and_redirect(resource_name, resource)
      else
        set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
        expire_session_data_after_sign_in!
        redirect_to after_inactive_sign_up_path_for(resource)
      end
    else
     clean_up_passwords(resource)
     respond_to do |format|
        format.html
        format.js 
    end
    end
  end

My application.js part :

jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})


$(document).ready(function() {
  $("#user_submit").submit(function() {
    $.post($(this).attr("action"), $(this).serialize(), null, "script");
      return false;
  })
})

My create.js.erb is just a simple

alert('ok');

I have overriden Devise registration form and controller. I keep getting on the create.html.erb instead of the create.js.erb

ps: since I'm pretty new to RubyonRails, any comment is welcomed.


The code wasn't wrong. I was using bad jquery js files.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜