Hey guys, I am trying to build an web app. I am running Rails 3. I just want to make a call to a controller method from my javascript(view part). Most of the links says AJAX. But I dont know whether its my search part on the internet causing me problems, but I just could not find a simple way of calling a Controller Method from Javascript. My javascript function: home.html.erb function test_call(val) { alert(val); new Ajax.Request(''/SessionsController/test_call_cont'', { method: ''post'', parameters: { menu_id: val, } }); } And in my sessioncontroller.rb def test_call_cont puts "Printing from Controller" end Where am I going wrong, should I have to include any js files, or is my syntax wrong? Totally confused. Please do guide me. Regards, Nikhil -- 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 26 November 2012 09:27, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey guys, I am trying to build an web app. I am running Rails 3. I just > want to make a call to a controller method from my javascript(view > part). Most of the links says AJAX. But I dont know whether its my > search part on the internet causing me problems, but I just could not > find a simple way of calling a Controller Method from Javascript. > > > My javascript function: > home.html.erb > > function test_call(val) > { > alert(val); > new Ajax.Request(''/SessionsController/test_call_cont'', {Ajax.Request takes a url. Is ''/SessionsController/test_call_cont'' a valid url? Perhaps ''/sessions/test_call_cont'' is what you want. Not thought that you are not ''calling a controller method'' but are initiating a request on that url. Colin> method: ''post'', > parameters: { > menu_id: val, > } > }); > } > > And in my sessioncontroller.rb > > def test_call_cont > puts "Printing from Controller" > end > > > Where am I going wrong, should I have to include any js files, or is my > syntax wrong? Totally confused. > > Please do guide me. > > Regards, > Nikhil > > -- > 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. > >-- 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.
Hi Colin, Im sorry but in the url, I am supposed to put up the path of my controller method right? Yes, my controller method is under main-application/app/views/sessions/. So should I put it up like sessions/test_call_cont in the request? I will also have to pass few parameters later on to that controller method and render new page based on some operations in that controller method(test_call_cont). Regards, Nikhil -- 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 26 November 2012 09:48, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Colin, > Im sorry but in the url, I am supposed to put up the path of my > controller method right? > > Yes, my controller method is under main-application/app/views/sessions/.You said earlier that the code is in sessions_controller.rb (actually you said sessioncontroller.rb, but I assumed you meant sessions_controller.rb) which should be in app/controllers, not app/views.> > So should I put it up like sessions/test_call_cont in the request?Yes, you will also have to set up the route in routes.rb of course.> I > will also have to pass few parameters later on to that controller method > and render new page based on some operations in that controller > method(test_call_cont).That is ok that is what controllers are for, but you should think of it as an action, not a method (though it is a method of the controller of course). Colin -- 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.
Colin, Sorry again. It was a typing mistake I believe. My controller is rightly placed in app/controllers. Though I have given the url as /sessions/test_call_cont, Nothing seems to be happening. I am not getting any error but neither I am getting the required output. Where can I have gone wrong? Nikhil -- 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.
And I have also routed the method in the routes.rb. I have invoke that url in routes.rb. But how can I achieve that from a javascript function is my concern. Awaiting your thoughts on this. Nikhil -- 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 26 November 2012 10:16, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin, > Sorry again. It was a typing mistake I believe. My controller is > rightly placed in app/controllers. Though I have given the url as > /sessions/test_call_cont, Nothing seems to be happening. I am not > getting any error but neither I am getting the required output. Where > can I have gone wrong?Do you see anything in log/development.log when you make the call? Colin> > Nikhil > > -- > 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. > >-- 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.
No Colin. I kept track of line numbers in development.log . After I make that click, there seems to be no action happening. -- 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.
Just a quickshot, but is your javascript function really triggered when clicking the link? Perhaps you could show that part of the view? Am 26.11.2012 13:09 schrieb "nikhil rn" <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> No Colin. I kept track of line numbers in development.log . After I > make that click, there seems to be no action happening. > > -- > 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. > > >-- 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.
If I put in an alert before the ajax call, the alert gets displayed. This is what you meant you by triggering the javascript right? <script type="text/javascript"> function test_call(val) { alert(val); new Ajax.Request(''/sessions/test_call_cont'', { method: ''post'', parameters: { menu_id: val } }); } </script> -- 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 Mon, Nov 26, 2012 at 8:19 PM, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> If I put in an alert before the ajax call, the alert gets displayed. > This is what you meant you by triggering the javascript right? > > <script type="text/javascript"> > > function test_call(val) > { > alert(val); > new Ajax.Request(''/sessions/test_call_cont'', { > method: ''post'', > parameters: { > menu_id: val > } > }); > } > > </script> >Are you sure that you''re using prototype?> > -- > 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. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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 Nov 26, 2012, at 5:27 AM, nikhil rn wrote:> And I have also routed the method in the routes.rb. I have invoke that > url in routes.rb. But how can I achieve that from a javascript function > is my concern. Awaiting your thoughts on this. > > NikhilWhat happens when you type that URL into a browser and try to visit it? You should see something, unless your controller does not include any handlers for a regular http request. Walter> > -- > 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. > >-- 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 26 November 2012 12:19, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> If I put in an alert before the ajax call, the alert gets displayed. > This is what you meant you by triggering the javascript right? > > <script type="text/javascript"> > > function test_call(val) > { > alert(val); > new Ajax.Request(''/sessions/test_call_cont'', { > method: ''post'', > parameters: { > menu_id: val > } > }); > } > > </script>Do you see an error if you run with a js debugger such as firebug in firefox? That is assuming you have checked that you are including prototype.js as suggested by Jim. Colin -- 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.
Jim ruther Nill wrote in post #1086470:> Are you sure that you''re using prototype?Jim, Yes I have put the latest prototype.js file in the app/assets/javascripts folder. Nikhil -- 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.
Walter Davis wrote in post #1086483:> On Nov 26, 2012, at 5:27 AM, nikhil rn wrote:> > What happens when you type that URL into a browser and try to visit it? > You should see something, unless your controller does not include any > handlers for a regular http request. > > WalterWalter, When I hit the url, I found out I get this error: Missing template sessions/test_call_cont, application/test_call_cont with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]} Have I missed any template? Nikhil -- 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.
Jim Ruther Nill
2012-Nov-27 04:39 UTC
Re: Re: Re: Call a controller method from Javascript
On Tue, Nov 27, 2012 at 12:32 PM, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Jim ruther Nill wrote in post #1086470: > > > Are you sure that you''re using prototype? > > Jim, > > > Yes I have put the latest prototype.js file in the > app/assets/javascripts folder. >ok. Are you using the asset pipeline? Also, what browser are you using? I suggest you use chrome because it has a default developer tool. Look at the js errors when you load the page. If there is nothing on the log file and there''s no response on the page, it most likely is an error with javascript.> > Nikhil > > -- > 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. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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.
Jim ruther Nill wrote in post #1086597:> ok. Are you using the asset pipeline? Also, what browser are you > using? > I suggest you use chrome because it has a default developer tool. Look > at the js errors when you load the page. If there is nothing on the > log file and there''s no response on the page, it most likely is an error > with javascript. >Jim, I am using firefox 11. I am afraid I cant change my browser. And sorry, how do I look for the js errors? I got nothing in the log file. Nikhil -- 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.
Jim, Forgot to mention on asset pipeline. Sorry again, I did not get by what you meant there. Nikhil -- 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.
Walter, The complete error message in my browser when the hit the URL is Template is missing Missing template sessions/test_call_cont, application/test_call_cont with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/nikhil/nikhil_ror/main_application/app/views" Have I given any wrong path? Nikhil -- 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.
Hey Guys, let me explain you all my scenario where I am stuck. I got a table filled with cells. When I right click on any cell, I got to display a context menu and then call a controller method on left clicking the context menu. I got to send in a parameter to my controller code and return what controller sends back. I am using jquery right click for my context menu. I have the clicked cell value. I just need to call a ruby controller method. This is my home.html.erb code: $(document).ready(function() { var currentCellText;/*this variable will have the clicked cell value*/ $("tbody td").mousedown(function(e) { currentCellText = $(this).text(); }); $.contextMenu({ selector: ''.context-menu-one'', callback: function(key, options) { var m = "clicked: " + currentCellText; window.console && console.log(m)|| test_call(currentCellText); }, items: { "Menu 1": {name: "Menu 1"}, "Menu 2": {name: "Menu 2"}, } }); }); function test_call(val) { alert(val); new Ajax.Request(''/sessions/test_call_cont'', { method: ''post'', parameters: { menu_id: val } }); } And my controller code is def test_call_cont puts "Printing from Controller" end Nikhil -- 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.
Jim Ruther Nill
2012-Nov-27 05:40 UTC
Re: Re: Re: Re: Call a controller method from Javascript
On Tue, Nov 27, 2012 at 12:44 PM, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Jim ruther Nill wrote in post #1086597: > > > ok. Are you using the asset pipeline? Also, what browser are you > > using? > > I suggest you use chrome because it has a default developer tool. Look > > at the js errors when you load the page. If there is nothing on the > > log file and there''s no response on the page, it most likely is an error > > with javascript. > > > > Jim, > I am using firefox 11. I am afraid I cant change my browser. And sorry, > how do I look for the js errors? I got nothing in the log file. >install firebug. after installing firebug, open the firebug console and reload the page. you should see the js errors on firebug after that.> > Nikhil > > -- > 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. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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 Tue, Nov 27, 2012 at 1:01 PM, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey Guys, let me explain you all my scenario where I am stuck. > > I got a table filled with cells. When I right click on any cell, I got > to display a context menu and then call a controller method on left > clicking the context menu. I got to send in a parameter to my controller > code and return what controller sends back. I am using jquery right >you''re using both prototype and jquery? why do you need both of them?> click for my context menu. I have the clicked cell value. I just need to > call a ruby controller method. > > > This is my home.html.erb code: > > > $(document).ready(function() { > var currentCellText;/*this variable will have the clicked cell value*/ > $("tbody td").mousedown(function(e) { > currentCellText = $(this).text(); > > }); > > $.contextMenu({ > > selector: ''.context-menu-one'', > callback: function(key, options) { > var m = "clicked: " + currentCellText; > window.console && console.log(m)|| > test_call(currentCellText); > }, > items: { > "Menu 1": {name: "Menu 1"}, > "Menu 2": {name: "Menu 2"}, > } > }); > }); > > > function test_call(val) > { > alert(val); > new Ajax.Request(''/sessions/test_call_cont'', { > method: ''post'', > parameters: { > menu_id: val > } > }); > } > > > > And my controller code is > > > def test_call_cont > puts "Printing from Controller" > end > > Nikhil > > -- > 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. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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.
Jim, If I put in prototype, my jquery doesnt work. So can i remove prototype? And yes Ill install FIREBUG. Nikhil -- 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 Tue, Nov 27, 2012 at 1:43 PM, nikhil rn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Jim, > > If I put in prototype, my jquery doesnt work. So can i remove prototype? > And yes Ill install FIREBUG. >yes. remove prototype. they have conflict since they both use $. there''s a way around this but if you don''t need both of them, it''d make your life easier. Look at http://api.jquery.com/jQuery.ajax/ for implementing ajax on jquery> > Nikhil > > -- > 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. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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.
Jim, I have removed the prototype.js file from app/assets/javascripts folder. I will look into the link which you have posted. Thanks, Nikhil -- 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.
Colin, I have installed firebug for my Browser and after I left click my right click menu option, I get the alert in the firebug console. No errors there too. But how do I call the controller method? Nikhil -- 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.
Colin, I have not put any javascript in application.js. If I have to put any, what should that script be trying acheive? Nikhil -- 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 Nov 27, 2012, at 12:54 AM, nikhil rn wrote:> Jim, > I have removed the prototype.js file from app/assets/javascripts > folder. I will look into the link which you have posted. > > Thanks, > > NikhilThe script that you posted originally was written using Prototype conventions, not jQuery. If you substitute jQuery for Prototype, you also need to alter your code to be jQuery-compliant. Now if you have more Prototype than jQuery in your hand-written code, you can make Rails use Prototype in place of jQuery for all of its core unobtrusive functions (:remote => true and so forth). Just make sure you have the proper (prototype) version of rails.js in your project, and only include prototype.js (not both prototype.js and jquery.js) in your application.html.erb template. Make a scratch Rails project with: rails new foo -j=prototype Have a look in that project for the relevant files. Walter> > -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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. For more options, visit https://groups.google.com/groups/opt_out.
Walter, I will change the prototype to jquery. Thanks. Nikhil -- 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.
Finally got it working. I thank you all for your support, time and patience. $(document).ready(function() { var currentCellText;/*this variable will have the clicked cell value*/ $("tbody td").mousedown(function(e) { currentCellText = $(this).text(); }); $.contextMenu({ selector: ''.context-menu-one'', callback: function(key, options) { var m = "clicked: " + currentCellText; window.console && console.log(m)|| test_call(currentCellText); }, items: { "Menu 1": {name: "Menu 1"}, "Menu 2": {name: "Menu 2"}, } }); }); function test_call(val) { $.ajax({ type: ''GET'', url:''/leave'', data:{ foo: val }, success:function(data){ alert(data); } }); } Nikhil -- 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.