# Form\_remote\_tag not displaying button

**URL:** <https://www.ruby-forum.com/t/form-remote-tag-not-displaying-button/79889>\
**Category:** Rails\
**Created:** [December 20, 2006, 11:04am UTC](https://www.ruby-forum.com/t/form-remote-tag-not-displaying-button/79889 "2006-12-20T11:04:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [December 20, 2006, 11:04am UTC](https://www.ruby-forum.com/t/form-remote-tag-not-displaying-button/79889/1 "2006-12-20T11:04:49Z")

</div>

Hello - I’m trying to use a form\_remote\_tag to make a submit button to  
fire off an Ajax call. When I add this form\_remote\_tag code I don’t  
see a submit button where there should be one.

I’m following the example given in the Agile Web D. book  
starting on page 122.

The code I’m using as follows

\<% form\_remote\_tag :url =\> { :action =\> :add\_to\_cart, :id =\> product }  
do %\>  
\<%= submit\_tag “Add to Cart” %\>  
\<% end %\>

I also have enabled the javascript\_include\_tag :defaults like this

\<%= javascript\_include\_tag :defaults %\>

Any ideas why the button wouldn’t show up?

Thanks,  
Clem

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [December 20, 2006, 11:27am UTC](https://www.ruby-forum.com/t/form-remote-tag-not-displaying-button/79889/2 "2006-12-20T11:27:12Z")

</div>

Clem R. wrote:

> Hello - I’m trying to use a form\_remote\_tag to make a submit button to  
> fire off an Ajax call. When I add this form\_remote\_tag code I don’t  
> see a submit button where there should be one.
> 
> I’m following the example given in the Agile Web D. book  
> starting on page 122.
> 
> The code I’m using as follows
> 
> \<% form\_remote\_tag :url =\> { :action =\> :add\_to\_cart, :id =\> product }  
> do %\>  
> \<%= submit\_tag “Add to Cart” %\>  
> \<% end %\>

form\_remote\_tag =\>  
[http://caboo.se/doc/classes/ActionView/Helpers/PrototypeHelper.html#M005162](http://caboo.se/doc/classes/ActionView/Helpers/PrototypeHelper.html#M005162)

This tag also has a non-block form.

Does that work ?

Alan

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [December 20, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/form-remote-tag-not-displaying-button/79889/3 "2006-12-20T20:29:35Z")

</div>

Clem,

Your code needs to look like this:

\<%= form\_remote\_tag :url =\> { :action =\> :add\_to\_cart, :id =\> product }  
do %\>  
\<%= submit\_tag “Add to Cart” %\>  
\<%= end\_form\_tag %\>

The \<% … %\> tags will evaluate the code between them without  
outputting the result into the HTML. The \<%= … %\> tags, on the other  
hand, will output the result.

Hope that helps,  
Matt Buck

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [December 20, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/form-remote-tag-not-displaying-button/79889/4 "2006-12-20T23:34:43Z")

</div>

Ok - it must be just the version of rails I was running:

this the the version that worked for me:

\<%= form\_remote\_tag :url =\> { :action =\> :add\_to\_cart, :id =\> product }  
%\>  
\<%= submit\_tag “Add to Cart” %\>  
\<%= end\_form\_tag %\>

Thanks so much for your help!

> > Clem,
> > 
> > Your code needs to look like this:
> > 
> > \<%= form\_remote\_tag :url =\> { :action =\> :add\_to\_cart, :id =\> product }  
> > do %\>  
> > \<%= submit\_tag “Add to Cart” %\>  
> > \<%= end\_form\_tag %\>
> > 
> > The \<% … %\> tags will evaluate the code between them without  
> > outputting the result into the HTML. The \<%= … %\> tags, on the other  
> > hand, will output the result.
> > 
> > Hope that helps,  
> > Matt Buck
> 
> Not exactly true…
> 
> On 1.2 RC1 or edge, the proper syntax for forms is:
> 
> \<% form\_tag :action =\> ‘foo’ do %\>  
> \<%= submit\_tag ‘Foo!’ %\>  
> \<% end %\>
> 
> If you combine this block form with the \<%= %\> and it bombs because it  
> does not return a valid ruby statement, causing a syntax error.
> 
> If you are not on edge rails, or RC1, then use the non block form\_tag:
> 
> \<%= form\_tag :action =\> ‘foo’ %\>  
> \<%= submit\_tag ‘Foo!’ %\>  
> \<%= end\_form\_tag %\>
> 
> I suspect you are using the block form with a version of rails that does  
> not support it. This makes whatever is inside your form tag simply  
> disappear. So either use the non-block form\_tag, or switch to RC1 or  
> edge rails.

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [December 20, 2006, 11:16pm UTC](https://www.ruby-forum.com/t/form-remote-tag-not-displaying-button/79889/5 "2006-12-20T23:16:45Z")

</div>

Matt Buck wrote:

> Clem,
> 
> Your code needs to look like this:
> 
> \<%= form\_remote\_tag :url =\> { :action =\> :add\_to\_cart, :id =\> product }  
> do %\>  
> \<%= submit\_tag “Add to Cart” %\>  
> \<%= end\_form\_tag %\>
> 
> The \<% … %\> tags will evaluate the code between them without  
> outputting the result into the HTML. The \<%= … %\> tags, on the other  
> hand, will output the result.
> 
> Hope that helps,  
> Matt Buck

Not exactly true…

On 1.2 RC1 or edge, the proper syntax for forms is:

\<% form\_tag :action =\> ‘foo’ do %\>  
\<%= submit\_tag ‘Foo!’ %\>  
\<% end %\>

If you combine this block form with the \<%= %\> and it bombs because it  
does not return a valid ruby statement, causing a syntax error.

If you are not on edge rails, or RC1, then use the non block form\_tag:

\<%= form\_tag :action =\> ‘foo’ %\>  
\<%= submit\_tag ‘Foo!’ %\>  
\<%= end\_form\_tag %\>

I suspect you are using the block form with a version of rails that does  
not support it. This makes whatever is inside your form tag simply  
disappear. So either use the non-block form\_tag, or switch to RC1 or  
edge rails.
