Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not override ajax() with Rails 3.1 #13

Closed
runlevel5 opened this issue Jul 10, 2011 · 1 comment
Closed

Could not override ajax() with Rails 3.1 #13

runlevel5 opened this issue Jul 10, 2011 · 1 comment

Comments

@runlevel5
Copy link

With jQuery 1.4.2 and Rails 3.x (manual method), I could override and bind the ajax to invoke callbacks on ajax success. However, this doesn't work with jquery-ujs 1.0.12 and Rails 3.1 (git) that leads to two requests to be invoked instead of one. I suspect this is related to issue #10 Here is an example:

  1. Generate test app

    rails new test123
    cd test123
    rails g scaffold states name:string abbr:string
    rake db:migrate
    
  2. Make sure we're usin the latest 3-1-stable by modify Gemfile:

    gem 'rails', :git => 'git://github.com/rails/rails.git', :branch => '3-1-stable'
    
  3. bundle install
  4. Modify following files:

app/controllers/states_controller.rb:

  def new
    @state = State.new

    respond_to do |format|
      format.html # new.html.erb
      format.js { render :text => 'hello world' } # we add this 
    end
  end

app/views/states/index.html.erb:

<%= link_to 'New State', new_state_path, :remote => true %>

app/assets/javascripts/states.js:

$(function(){
    $('a[data-remote=true]').live('click', function(){
        $.get(this.href, function(data) {
          alert(data);
        });
        return false;
    });
});

With the help of Firebug, it is indicated that there are 2 requests invoked. This might explain that the binding is not successful.

@JangoSteve
Copy link
Member

This should be posted over in the jquery-ujs issues, since this is a problem with the javascript and not the gem or installer itself.

See issue over on jquery-ujs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants