# Replace a form\_for and f.submit with a link\_to

**URL:** <https://www.ruby-forum.com/t/replace-a-form-for-and-f-submit-with-a-link-to/142724>\
**Category:** Rails\
**Created:** [July 10, 2008, 9:26pm UTC](https://www.ruby-forum.com/t/replace-a-form-for-and-f-submit-with-a-link-to/142724 "2008-07-10T21:26:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [July 10, 2008, 9:26pm UTC](https://www.ruby-forum.com/t/replace-a-form-for-and-f-submit-with-a-link-to/142724/1 "2008-07-10T21:26:09Z")

</div>

I have a helper which puts a form\_for in the view (from holding it in an  
ERB tag). It looks like this;

ERB.new(%{  
\<% form\_for(following, :url =\> user\_follower\_path(followee, follower))  
do |f| %\>  
\<%= f.hidden\_field :status, :value =\> 0 %\>  
\<%= f.submit ‘Block’, :class =\> “bar\_button block\_button” %\>  
\<% end %\>  
}).result(binding)

I want to replace this with a link\_to, but I don’t know if a link\_to  
could handle the status change that is sent (using the hidden\_field tag)  
through the form\_for. This example doesn’t work, but I was wondering if  
someone knows how I can achieve something similar(?);

“#{link\_to “Block”, {:controller =\> “followers”, :action =\> “update”,  
:user\_id =\> followee, :id =\> follower, :status =\> 0}, :confirm =\> “Are  
you sure?”, :class =\> “bar\_button block\_button”}”

Another option is to keep the form\_for but to use a link\_to to perform  
the submit on the form. Essentially, we’re trying to avoid having an  
input element in the DOM - we just want a simple anchor tag. Is this  
possible?

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [May 11, 2009, 11:06am UTC](https://www.ruby-forum.com/t/replace-a-form-for-and-f-submit-with-a-link-to/142724/2 "2009-05-11T11:06:30Z")

</div>

first, put html element id using :html

like this:

`<% form_for(following, :url => user_follower_path(followee,
follower), :html => {:id => “my_form”}) do |f| %>`

and use below code in block.

`<%= link_to_function “submit”,
“javascript:document.getElementById(“my_form”).submit(); return
false” %>`

it’s old trick so work very well.

On 2008ë…„7ì›”11ì¼, ì˜¤ì „4ì‹œ26ë¶„, Neil C. \<rails-mailing-l…@andreas-
