Rails 2 to Rails 3:Using Link_To Instead of Link_To_Remote (Including Remote and Update)

Rails 2 to Rails 3 : using link_to instead of link_to_remote (including remote and update)

The :update option isn't supported by the new link_to :remote => true.

You will either have to

  • use the legacy plugin
  • write the JS/AJAX yourself instead of using :remote => true
  • use render :update { |page| p.replace_html ... }

Rails 3 upgrade link_to :remote :with options

I think it has been removed from Rails 3, as it goes against the principle of non-obstrusive javascript.

So, you should try to find another way to achieve whatever you want....

Take a look here: http://railscasts.com/episodes/205-unobtrusive-javascript?view=asciicast

Rails 3 - How to send data on link_to :remote= true?

They say its no longer supported in this answer on How to send Javascript Variable to a controller's action with the link_to helper?

Update content with link_to :remote = true

Finally solved this whole mess:

Created a Javascript file to bind the callbacks

document.observe("dom:loaded", function(){
$('semantic')
.observe("ajax:success", function(evt, data, status, xhr){
alert("success");
// Since we're dealing with ajax call, we'll handle the response as JavaScript
eval(xhr.responseText);
})
.observe("ajax:error", function(evt, data, status, xhr){
alert("failed");
// Insert a custom error message when something goes wrong
$('semantic').replace();
$('semantic').insert('<p>A problem occured retrieving the information.</p>');
});
});

Relies on the Prototype.js file included, most web examples use jquery, so had to adapt several calls to be conform to the prototype standards.

Create the js.erb file

$('semantic').innerHTML = "";
$('semantic').insert("<p><%= CGI::escape(@country.abstract.value) %></p><p><%= CGI::escape(@country.comment.value)%></p><p>Currency: <%= CGI::escape(@country.currency.value) %></p><p>Population: <%= CGI::escape(@country.population.value) %></p><p>Capital: <%= CGI::escape(@country.capital.value) %></p>");

The problem here was the $('semantic').replace(), this was for some reason removing the element instead of clearing it.

With these changes the remote call is working as intended.

rails link_to :remote

You can bind to ajax calls like this:

<%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %>
<i class="icon-trash"></i>
<% end %>

$('.link-delete').bind('ajax:beforeSend', function() {
$('#mySpinner').show();
});

$('.link-delete').bind('ajax:complete', function() {
$('#mySpinner').hide();
});

how to work on ajax using link to remote in rails 3.2

Try the following in your routes.rb

resources assets do
post :add_group, :on => :member
end

And change your form to use:

add_group_assets_path(@asset.id, :group_id => @group.id)

How do I use link_to_remote with a form as the remote URL?

You create the form as normal but you use the remote_form_for helper in the place of the form_for and the remote_form_tag in the place of form_tag. This will submit the form via ajax.

Documenation at: http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html

Update: Example:

In your form (using haml):

= remote_form_for @customer, :url => customer_path(@customer), :complete => "doSomething(request)" do |f|
%p
First Name<br>
= f.text_field :first_name
%p
Last Name<br>
= f.text_field :last_name
= submit_tag "Update"

For your fade functions, you would need to use scriptaculous or jquery. Scriptaculous comes packaged with rails and is currently the default. For that, your javascript would be something like this:

function doSomething(request){
Effect.fade('some_div');
}

more on scriptaculous: http://wiki.github.com/madrobby/scriptaculous/

How to include class in link_to remote?

Try changing it to:

<%= link_to new_subcomment_path(:response_id => response.id), {remote: true}, {class: "subcomment_link", id: "reply_new_subcomment#{response.id}"} do %>

Usually the tag options come before the html options.



Related Topics



Leave a reply



Submit