Javascript talks to rails

i am trying to do this:

var name =“Some Value”
mygrid.getCombo(2).get(value);
alert(encodeURIComponent(’<%=Product.find_by_name(’+name+’)%>’));

all the code is good, the problem is that var name seems that is not
sendin

how can i send a javascript var to ruby??

Regards,

Could you shed more light on what you’re trying to do?

I think you’ll need an observe_field call perhaps:

http://noobkit.com/show/ruby/rails/rails-edge/actionpack-edge/actionview/helpers/prototypehelper/observe_field.html

Well i am working with a datagrid in javascript and when a value is
inserted in a column, i need to pass this value to the controller
dynamically.
this is the reason i am trying to do this, to see if the value is being
passed correct:
var product = ‘value’;
alert(encodeURIComponent(’<%=Product.find_by_name(’+product+’)%>’));

other way i have been trying is assigning the value to a session
variable by ajax method.

var product = ‘value’;
new Ajax.Request(’<%= “/” + request.path_parameters[“controller”] +
“/setActualProduct/?pCode=” %>’+product,{);

method: setActualProduct
change a session variable value

The problem is that this session var is render the firsttime you enter
the page
<%pActual=session[:pActual]%>
alert(’<%=pActual%>’);

maybe i will need some observer but to a var instead to a field…

any ideas?

the answer is Ajax + RJS.

var name =“Some Value”
mygrid.getCombo(2).get(value);
alert(encodeURIComponent(’<%=Product.find_by_name(’+name+’)%>’));

<%= remote_function(:url => {, :name => name}) %>

def

render :update do |page|
page.alert(Product.find_by_name(params[:name]).id)
end

end

Thanks Keynan, i am doing an alert(), but what i really need is to pass
this value to javascript function.