[Rails] Re: Call a controller method from Javascript
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home