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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Maybe try in controller: def getDiagram respond_to do |format| format.js end end On Wednesday, October 24, 2012 8:40:24 PM UTC+2, Ruby-Forum.com User wrote:> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Rbq35V6EY2cJ. For more options, visit https://groups.google.com/groups/opt_out.
On Wednesday, October 24, 2012 7:40:24 PM UTC+1, Ruby-Forum.com User wrote:> > 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"); > }; > } >This javascript is syntactically incorrect - you''re not closing the parens you open just after "bind" Also if you want to render nothing you do need to explicitly say that (eg render :nothing => true) or rails will complain that there is no template Fred> >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/c5f5jNuM62EJ. For more options, visit https://groups.google.com/groups/opt_out.
Jason Walsh wrote in post #1080993:> 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 > > JasonWhat I have noticed is that 1. The javascript syntax is not correct 2. You didn''t specify a controller from the link 3. It is probably make more sense to test with Json response using respond_to :json respond_with { :status => ''okay'' } -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
AndreM wrote in post #1081168:> Maybe try in controller: > > def getDiagram > > respond_to do |format| > format.js > end > > endHi Andre Tried that - dont get error but renders a blank template. My main concern is why the event isnt firing and showing the alert. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung wrote in post #1081170:> On Wednesday, October 24, 2012 7:40:24 PM UTC+1, Ruby-Forum.com User > wrote: >> alert("success"); >> }; >> } >> > > This javascript is syntactically incorrect - you''re not closing the > parens > you open just after "bind" > Also if you want to render nothing you do need to explicitly say that > (eg > render :nothing => true) or rails will complain that there is no > template > > FredThanks Fred I spotted that using Firebug, but still makes no difference. When setting render :nothing => true it just renders a blank template which is not what i want. The ajax:success event is not firing either -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
webber han wrote in post #1081214:> Jason Walsh wrote in post #1080993: >> 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 > > What I have noticed is that > 1. The javascript syntax is not correct > 2. You didn''t specify a controller from the link > 3. It is probably make more sense to test with Json response using > respond_to :json > respond_with { :status => ''okay'' }Thanks Webber 1. Noticed the missing bracket and fixed. 2. Have set a route as follows: match ''/getdiagram'', :to => ''prosesses#getDiagram'' It seems to be executing the right controller/action from the error message i get 3. Tried that but get: c:/Users/Jason/rails_projects/procstor/app/controllers/prosesses_controller.rb:123: syntax error, unexpected tASSOC, expecting ''}'' respond_with { :status => ''okay'' } ^ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Oct 25, 2012, at 4:32 PM, Jason Walsh wrote:> webber han wrote in post #1081214: >> Jason Walsh wrote in post #1080993: >>> 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 >> >> What I have noticed is that >> 1. The javascript syntax is not correct >> 2. You didn''t specify a controller from the link >> 3. It is probably make more sense to test with Json response using >> respond_to :json >> respond_with { :status => ''okay'' } > > Thanks Webber > > 1. Noticed the missing bracket and fixed. > 2. Have set a route as follows: > match ''/getdiagram'', :to => ''prosesses#getDiagram'' > It seems to be executing the right controller/action from the error > message i get > 3. Tried that but get: > c:/Users/Jason/rails_projects/procstor/app/controllers/prosesses_controller.rb:123: > syntax error, unexpected tASSOC, expecting ''}'' > respond_with { :status => ''okay'' } > ^The parser sees this line as a method with a block and then the => is confusing (not allowed there, it isn''t in a Hash) Either of these changes will do what you expect: respond_with({ :status => ''okay'' }) # no longer looks like a block respond_with :status => ''okay'' # must be a hash literal respond_with( :status => ''okay'' ) # must be a hash literal Although the value for :status might need to be ''OK'' or 200 rather than ''okay'' and you need a respond_to in the controller. http://apidock.com/rails/ActionController/MimeResponds/respond_with -Rob -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.