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.
12bba63ac22ff2c787d49a1b88463182?d=identicon&s=25 Eddie Ridwan (eddier)
on 2009-05-01 06: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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-01 09:51
(Received via mailing list)
On May 1, 5:17 am, Eddie Ridwan <rails-mailing-l...@andreas-s.net>
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
782b01570270ab10543bc25a258d7ea8?d=identicon&s=25 Dmitry Sokurenko (Guest)
on 2009-05-01 11: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
12bba63ac22ff2c787d49a1b88463182?d=identicon&s=25 Eddie Ridwan (eddier)
on 2009-05-01 12:12
Dmitry Sokurenko 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.