# How can i use link\_to\_remote with in form\_for

**URL:** <https://www.ruby-forum.com/t/how-can-i-use-link-to-remote-with-in-form-for/143032>\
**Category:** Rails\
**Created:** [July 14, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/how-can-i-use-link-to-remote-with-in-form-for/143032 "2008-07-14T17:23:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [July 14, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/how-can-i-use-link-to-remote-with-in-form-for/143032/1 "2008-07-14T17:23:08Z")

</div>

Hi  
anybody plz help me how can i use link\_to\_remote with in form\_for… i  
tried but no luck… if i use form\_tag i can able to use link\_to\_remote  
and made ajax call.but i need to use form\_for …can anyone help me how  
can i do with this.Thanks in advance.

---

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [July 14, 2008, 5:27pm UTC](https://www.ruby-forum.com/t/how-can-i-use-link-to-remote-with-in-form-for/143032/2 "2008-07-14T17:27:00Z")

</div>

On 14 Jul 2008, at 16:23, Palani K. wrote:

> Hi  
> anybody plz help me how can i use link\_to\_remote with in  
> form\_for… i  
> tried but no luck… if i use form\_tag i can able to use  
> link\_to\_remote  
> and made ajax call.but i need to use form\_for …can anyone help me  
> how  
> can i do with this.Thanks in advance.

A little detail would help (ie what doesn’t work if you just bung a  
link\_to\_remote in your form ?)  
Fred

---

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [July 14, 2008, 5:27pm UTC](https://www.ruby-forum.com/t/how-can-i-use-link-to-remote-with-in-form-for/143032/3 "2008-07-14T17:27:01Z")

</div>

why not use form\_remote\_for ?  
gives you an ajax call to and the form\_for stuff

anyway, please give us more details, what you want to  
do, and/or what exactly your problem is.

for link\_to\_remote it doesn’t matter, if it’s within a form  
or not and it’ll display & work as everywhere else.  
so if you have problems, they’re specific to your code.

---

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [July 14, 2008, 6:26pm UTC](https://www.ruby-forum.com/t/how-can-i-use-link-to-remote-with-in-form-for/143032/4 "2008-07-14T18:26:02Z")

</div>

On 14 Jul 2008, at 17:12, Palani K. wrote:

> =\>‘Available’},:with =\> “‘user\_name=’+$F(‘username’)”,:complete =\>  
> ‘alert(request.responseText)’

The problem here is that the id of your username textfield isn’t  
username (it will be something like user\_username). Check your html.

Fred

---

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [July 14, 2008, 6:12pm UTC](https://www.ruby-forum.com/t/how-can-i-use-link-to-remote-with-in-form-for/143032/5 "2008-07-14T18:12:45Z")

</div>

Palani K. wrote:

> Hi  
> anybody plz help me how can i use link\_to\_remote with in form\_for… i  
> tried but no luck… if i use form\_tag i can able to use link\_to\_remote  
> and made ajax call.but i need to use form\_for …can anyone help me how  
> can i do with this.Thanks in advance.

Hi  
Actually i work user avilability check.ie) the newuser choose the  
username and check whether his username already available or not.

```
my form looks:-

 <% form_for :user,@user, :url => {:controller => 'account', :action 

```

=\> ‘signup\_new’} do |f| %\>

 Choose Username : \<%= f.text\_field 'username', :class =\> "text-n", :tabindex =\> 2 %\> \<% link\_to\_remote "check",url =\> {:controller =\> 'account',:action =\>'Available'},:with =\> "'user\_name='+$F('username')",:complete =\> 'alert(request.responseText)'

In controller:

def Available  
@u= User.find\_by\_username(params[:user\_name])  
if @u !=nil  
if request.xhr?

```
      render(:text => "User Name Already exist" , :layout => false)
    else
     render(:text => "User Name doesn't exist ",:layout => false )

  end
end

```

end

```
 If i use form_tag it works fine (ie.Alert box popup with ajax 

```

response message)…If I use form\_for\_remote,form\_remote\_for the ajax  
call doesn’t made this is my exact problem. I need use the form which  
involves model also.

---

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [July 14, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/how-can-i-use-link-to-remote-with-in-form-for/143032/6 "2008-07-14T18:45:59Z")

</div>

Frederick C. wrote:

> On 14 Jul 2008, at 17:12, Palani K. wrote:
> 
> > =\>‘Available’},:with =\> “‘user\_name=’+$F(‘username’)”,:complete =\>  
> > ‘alert(request.responseText)’
> 
> The problem here is that the id of your username textfield isn’t  
> username (it will be something like user\_username). Check your html.
> 
> Fred

Hi Fred  
Thank you so much man…now its working for me… the is  
error exactly what you specify. Thanks you so much
