# Sending parameters to ruby method from javascript

**URL:** <https://www.ruby-forum.com/t/sending-parameters-to-ruby-method-from-javascript/139278>\
**Category:** Rails\
**Created:** [June 2, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/sending-parameters-to-ruby-method-from-javascript/139278 "2008-06-02T15:36:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pandiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9de0a6/32.png) [@pandiri](https://www.ruby-forum.com/u/pandiri)\
**Post date:** [June 2, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/sending-parameters-to-ruby-method-from-javascript/139278/1 "2008-06-02T15:36:01Z")

</div>

HI THERE,  
In my .rhtml file I have some links.I need to invoke a ruby  
method(controller’s method/Helper method) and send link text as a  
parameter on clicking the link.  
Is it Possible…!

Thanks In Advance

---

<div class="post-metadata">

**Author:** ![pandiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9de0a6/32.png) [@pandiri](https://www.ruby-forum.com/u/pandiri)\
**Post date:** [June 2, 2008, 3:51pm UTC](https://www.ruby-forum.com/t/sending-parameters-to-ruby-method-from-javascript/139278/2 "2008-06-02T15:51:33Z")

</div>

sure:

link\_to(“my\_text”, { :action =\> “your\_action”, :some\_param =\> “my\_text”  
})

this would give you “my\_text” as params[:some\_param] in your action. You  
can add any number of parameters that way with whatever content you  
want.

---

<div class="post-metadata">

**Author:** ![pandiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9de0a6/32.png) [@pandiri](https://www.ruby-forum.com/u/pandiri)\
**Post date:** [June 2, 2008, 4:19pm UTC](https://www.ruby-forum.com/t/sending-parameters-to-ruby-method-from-javascript/139278/3 "2008-06-02T16:19:52Z")

</div>

Yes it is possible.

link\_to\_function(name, \*args, &block)

Returns a link that will trigger a JavaScript function using the  
onclick handler and return false after the fact.

The function argument can be omitted in favor of an update\_page block,  
which evaluates to a string when the template is rendered (instead of  
making an Ajax request first).

(Refer  
[http://api.rubyonrails.com/classes/ActionView/Helpers/JavaScriptHelper.html#M001061](http://api.rubyonrails.com/classes/ActionView/Helpers/JavaScriptHelper.html#M001061)  
)

Thanks  
-Pavan

On Mon, Jun 2, 2008 at 6:51 AM, Thorsten M.

---

<div class="post-metadata">

**Author:** ![pandiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9de0a6/32.png) [@pandiri](https://www.ruby-forum.com/u/pandiri)\
**Post date:** [June 3, 2008, 8:58am UTC](https://www.ruby-forum.com/t/sending-parameters-to-ruby-method-from-javascript/139278/4 "2008-06-03T08:58:58Z")

</div>

Thanks for the reply…

```
   I am sorry for asking the question in the worst way.My question 

```

is  
can I pass a javascript variable to a Ruby Method call.?

Thank You.

Pavankumar Kulkarni wrote:

> Yes it is possible.
> 
> link\_to\_function(name, \*args, &block)
> 
> Returns a link that will trigger a JavaScript function using the  
> onclick handler and return false after the fact.
> 
> The function argument can be omitted in favor of an update\_page block,  
> which evaluates to a string when the template is rendered (instead of  
> making an Ajax request first).
> 
> (Refer  
> [Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/JavaScriptHelper.html#M001061)  
> )
> 
> Thanks  
> -Pavan
> 
> On Mon, Jun 2, 2008 at 6:51 AM, Thorsten M.
