# Req: Method executed in link\_to

**URL:** <https://www.ruby-forum.com/t/req-method-executed-in-link-to/194943>\
**Category:** Rails\
**Created:** [September 14, 2010, 6:00am UTC](https://www.ruby-forum.com/t/req-method-executed-in-link-to/194943 "2010-09-14T06:00:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 14, 2010, 6:00am UTC](https://www.ruby-forum.com/t/req-method-executed-in-link-to/194943/1 "2010-09-14T06:00:33Z")

</div>

Group,

This might very well be Rails 102 stuff, but it’s doing my little head  
in.

Simple request - I want to create a link within my View to fire off a  
system call to run an external program.

In this example it’s pretty easy - run a Windows system command that  
simply starts something (it’s not what I’m trying to achieve but it’s  
an easy debug method):

def method\_to\_run  
system(‘start dir \> test.txt’)  
end

How the _heck_ do I link to this method within my View?

A simple \<%= link\_to feature, :method =\> method\_to\_run %\> results in  
the following error:

```
undefined local variable or method `method_to_run' for #<#:0x46c1808>
```

Jason

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 14, 2010, 6:29am UTC](https://www.ruby-forum.com/t/req-method-executed-in-link-to/194943/2 "2010-09-14T06:29:14Z")

</div>

Reference on link\_to here:

> **[ActionView::Helpers::UrlHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to)**
>
> Provides a set of methods for making links and getting URLs that depend on the routing subsystem (see ActionDispatch::Routing).

:method is used for specifying HTTP method such as POST, GET, etc.

The parameter that you are passing (method\_to\_run) is not a valid value  
for  
:method.

I suggest you define a controller and invoke one of its methods through  
the  
link.

Example:  
link\_to “Feature”, :controller =\> “mycontroller”, :action =\>  
“method\_to\_run”

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 14, 2010, 1:31pm UTC](https://www.ruby-forum.com/t/req-method-executed-in-link-to/194943/3 "2010-09-14T13:31:14Z")

</div>

Of course, I should have known that :method was for the HTTP method.

Thanks.

I guess i just need to write the correct routes now.
