Forum: Ruby on Rails button_to_remote problem on 2.3.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eddie R. (Guest)
on 2009-05-01 08:17
Sorry about the previous aborted post.. Here is the full post.

I have a link_to_remote call that works as expected (using Rails 2.3.2):

<%= link_to_remote "-", { :url => { :action => :remove_from_cart, :id =>
cart_item.product} }, { :href => url_for(:action => :remove_from_cart,
:id => cart_item.product) } %>

It fallsback correctly when javascript is not enabled.

However, substituting with button_to_remote, does not behave correctly:

<%= button_to_remote "-", { :url => { :action => :remove_from_cart, :id
=> cart_item.product} }, { :href => url_for(:action =>
:remove_from_cart, :id => cart_item.product) } %>

With javascript enabled it works fine. But if javascript disabled, the
fallback :href url is not followed. I.e. it does not work.

Has anybody encountered this problem. Aren't both meant to have exactly
the same options?

Thanks for any suggestions.
Frederick C. (Guest)
on 2009-05-01 11:51
(Received via mailing list)
On May 1, 5:17 am, Eddie R. <removed_email_address@domain.invalid>
wrote:
> However, substituting with button_to_remote, does not behave correctly:
>
> <%= button_to_remote "-", { :url => { :action => :remove_from_cart, :id
> => cart_item.product} }, { :href => url_for(:action =>
> :remove_from_cart, :id => cart_item.product) } %>
>
> With javascript enabled it works fine. But if javascript disabled, the
> fallback :href url is not followed. I.e. it does not work.
>
Have you looked at the generated html to see what might be amiss?

Fred
Dmitry S. (Guest)
on 2009-05-01 13:42
(Received via mailing list)
Definetely it won't work, just because standalone buttons should not
do anything when javascript is disabled. That's by design.

Dmitry
Eddie R. (Guest)
on 2009-05-01 14:12
Dmitry S. wrote:
> Definetely it won't work, just because standalone buttons should not
> do anything when javascript is disabled. That's by design.
>
> Dmitry

So it appears. button_to_remote generates the code:

<input href="/store/remove_from_cart/1" onclick="new
Ajax.Request('/store/remove_from_cart/1', {asynchronous:true,
evalScripts:true, parameters:'authenticity_token=' +
encodeURIComponent('xzGTsqm4ySuhtDKGQq4SIwVn7oIipLPmBq21CUOoQvY=')});"
type="button" value="-" />
  </td>

which would not recognise the href. I was lulled by the description in
the API docs, believing that it says the button_to_remote behaves the
same as link_to_remote. With hindsight and closer reading, it only says
that the :url and callbacks are the same (ie silent on the Javascript
degradation).

Thanks.
This topic is locked and can not be replied to.