Weird problem with RUBY and AJAX (form_remote_tag and submit

Hello,

I am trying to implement the depot sample application of “Agile
programming with rails”, everrithing goes good until came to AJAX
stuff,

When I changed the button_to for submit_tag I have no HTML code
generated for invoking the action using AJAX, I read the
troubleshooting section and everything is OK, any Idea of what could be

happening?

The code in index.rhml is

<% form_remote_tag :url => {:action => :add_to_cart, :id => product

} do %>

  <%= submit_tag "Add to Cart" %>
<% end %>

and the resulting form has nothing, just a couple of blank lines in the

place that should show the button.

Thank you

Mike wrote:

Hello,

The code in index.rhml is

<% form_remote_tag :url => {:action => :add_to_cart, :id => product

and the resulting form has nothing, just a couple of blank lines in the

place that should show the button.

You left off the = on the opening <%, so the form_remote_tag line
doesn’t output anything.

In general, you use <% for “figuring things out”, like setting a
variable to the result of a calculation, and you use <%= for lines where
you want the stuff in there to create some output into the html stream.

jp

Jeff P. ha escrito:

jp


Posted via http://www.ruby-forum.com/.

Tried also that but didn’t work, still trying.

Thank you

Mike wrote:

Jeff P. ha escrito:

jp


Posted via http://www.ruby-forum.com/.

Tried also that but didn’t work, still trying.

Thank you

Oh! I stopped reading when I “saw” the missing =

You are using form_remote_tag the way one would use form_for.
form_remote_tag doesn’t use a do/end block. Try form_remote_for.

jp

Mike wrote:

Hello,

I am trying to implement the depot sample application of “Agile
programming with rails”, everrithing goes good until came to AJAX
stuff,

When I changed the button_to for submit_tag I have no HTML code
generated for invoking the action using AJAX, I read the
troubleshooting section and everything is OK, any Idea of what could be

happening?

The code in index.rhml is

<% form_remote_tag :url => {:action => :add_to_cart, :id => product

} do %>

  <%= submit_tag "Add to Cart" %>
<% end %>

and the resulting form has nothing, just a couple of blank lines in the

place that should show the button.

Thank you

<%= form_remote_tag :url => {:action => :add_to_cart, :id => product }
%>

<%= end_form_tag %>

Jeff P. wrote:

Mike wrote:

Jeff P. ha escrito:

jp


Posted via http://www.ruby-forum.com/.

Tried also that but didn’t work, still trying.

Thank you

Oh! I stopped reading when I “saw” the missing =

You are using form_remote_tag the way one would use form_for.
form_remote_tag doesn’t use a do/end block. Try form_remote_for.

jp

<% form_remote_tag do %>
<%= text_field ‘foo’, ‘bar’ %>
<% end %>

is the proper way to do forms as of 1.2/edge

So if you are using that style, be sure you are on 1.2 or edge rails.
Otherwise everything inside your form block will dissapear.