Friday, October 26, 2012

[Rails] Re: Ajax test not working

dude, you miss a lot.
in *.js.erb
 blablabla, looks fine
in controler
 you miss format.js
in router
 you miss
    resource contoler_name do
      get: :getDiagram on :member  # or post or whatever, that will be your method name in link_to tag
    end
in erb tamplate
 <%= link_to "Button", controler_action_path, method: get, remote: true =>
that all, you should try it now, and should works


在 2012年10月25日星期四UTC+8上午2时40分24秒,Ruby-Forum.com User写道:
Am having real probs trying to use Ajax with my Rails app. I have set up
a test as

follows:

in javascript file:

window.onload = function() {
    $('#test').bind('ajax:success', function() {
        alert("success");
    };
}
in view:

<%= link_to "test", { :action => :getDiagram }, :remote => true, :id =>
"test" %>
in controller:

def getDiagram

end

Now I know this looks odd with the empty controller action, but I would
expect this code to just show a popup window with 'success' and leave
the current page loaded when the link is clicked? Instead i get the
missing template message like its trying to load a page synchronously
rather than using ajax?

Can anyone get my test to work? Do I need to upgrade or add a gem file?

Thanks in advance

Jason

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/bzGL-S7U93cJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate