Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
how to pass value from the javascript to controller
4 Posts
how to pass value from the javascript to controller

Hi i am work on image editing user can edit the image and set the description in that i want to know about width,height etc at run time i find it through the javascript but how i pass it to controller

document.getElementById('test1').style.hieght

Thanks

Amit,

It sounds to me like you need to write your own AJAX function to post the parameters to an action in a controller. I won't go into details of AJAX here, but you'll want to read up on the basics of AJAX. There are no Rails specific helpers to turn an image into a range-based selection tool that I'm aware of, much less one that will let you pass that value back into an action.

However, you can call remote controller actions using link_to_remote() in Rails. Check the documentation. It creates an href that is clickable, and posts the results back to the server using AJAX, so the page does not refresh.

Kevin Elliott "WeLikeFood Beta":http://www.welikefood.com/

Kevin Elliott, in this project user can resize the image hieght and wieght and drag the image so i have to store that width hieght at run time so i use the javascript for that just like this funcation give me the hieght of div

document.getElementById('test1').style.hieght
i want to store the hieght of the div in the database the problem is that how i pass these value to the controller or how to right in the view part .

Amit Agarwal

Amit,

I am assuming you are using Prototype - if not, the solution using JQuery or whatever else should be similar. As Kevin said, you should post the data to an action in a controller with AJAX. Check out the "Prototype Ajax.Request docs here":http://www.prototypejs.org/api/ajax/request.

HTH, Peter

4 Posts
Login to add your message