No, the controller is written in Ruby and runs on the server.
Javascript runs in the browser. Why do you want to write the function
in javascript, why not just use Ruby?
Colin
>
> for example:
>
> <script>
> function test() {
> return 'Hello World';
> }
> </script>
>
> And than i would like in my controller to do something like this:
> #controller
> render :text => call "test();"
>
> There is a way to do something like this?
>
> Thanks
>
> Fernando
>
> --
> 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 rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
Please don't top post, it makes it difficult to follow the thread.
Insert your reply at appropriate points in previous post. Thanks.
>
> Because i need to get the content of a div in the page.
Think about when the controller and view code is run. The
controller/view code is completely run *before* it is sent to the
browser. Therefore you cannot access anything in a div in the
controller, because the div does not exist until it is sent to the
browser. If you know what is *going* to be in the div then you can
use that in the controller. Once the view has been built it is sent
to the browser and then you can only run javascript.
Colin
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
The same way you always send params to your controllers. Either put them
in the query string (for GET requests) or put them in the request body
as form data (for POST or PUT requests).
Then access them from the params hash in the controller
(params[:some_value]).
--
Posted via http://www.ruby-forum.com/.
--
> Robert,
>
> Can you give me an example of how to do this
>
> "The same way you always send params to your controllers. Either put
> them
> in the query string (for GET requests) or put them in the request body
> as form data (for POST or PUT requests)."
>
> I dont know how to do this manually, usually i just always send with
> a rails helper.
Are you using Prototype or jQuery? In Prototype, you get the content
of form elements using
var data = $F('theIdOfTheFormElement');
If you're not putting the user's data in a form field (even a hidden
one) then you will need to do something hacky like
var data = $('theIdOfTheElement').innerHTML.stripTags();
Then to send it to your controller, you do something like this:
new Ajax.Request('/url/of/endpoint',{parameters:{your_rails_parameter:
data}});
To do the same, but update a portion of the page with whatever HTML
your Rails request returns, you substitute Updater for Request, and
add the ID of the element you need to update:
new Ajax.Updater('theIdOfTheElementYouWantToUpdate', '/url/of/
endpoint', {parameters:{your_rails_parameter: data}});
Note that Updater does not replace the outer box, only the contents of
the box you indicate with your ID. Also, Updater does not update form
fields (you can replace them, but the correct thing to do is to use
Ajax.Request and a callback function onSuccess to update anything
besides a DIV or another container element.
Walter
>
> Thanks,
>
> Fernando
>
> 2011/1/17 Robert Walker <li...@ruby-forum.com>
> Fernando Leandro wrote in post #975487:
> > How can i do this? How can i send params for my controller with
> > javascript?
>
> The same way you always send params to your controllers. Either put
> them
> in the query string (for GET requests) or put them in the request body
> as form data (for POST or PUT requests).
>
> Then access them from the params hash in the controller
> (params[:some_value]).
>
> --
> 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-
> ta...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
> .
>
>
>
> --
> 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-
> ta...@googlegroups.com.
Hello guys,
I would like to know if i can call a javascript function directly from my controller and get the return of the function.
for example:
<script>
function test() {
return 'Hello World';
}
</script>
And than i would like in my controller to do something like this:
#controller
render :text => call "test();"
There is a way to do something like this?
Thanks
Fernando
--
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 rubyonra...@googlegroups.com.