Rectangle 27 1

Plain :remote => true makes a request that accepts application/javascript, */* (or something similar). But your controller does not respond to javascript, so it tries to render html template.

json
= form_for [@list, @item], :remote => true, :html => {:class => 'form-inline', 'data-type' => 'json'} do |f|

Thanks Dimuch, i wasn't sure what was happening there and understanding that the controller was trying to render HTML helped me hone in on the solution. I've posted an update above. Just required some changes to the controller code to at least get the alert working.

ruby on rails - form returned from AJAX request is not recognized as '...

ruby-on-rails ajax ruby-on-rails-3 ujs
Rectangle 27 0

The problem is happening with the capybara-webkit driver and works correctly in Chrome.

well that was a suggestion,you could have commented on my answer rather than giving negative marking @carolclarinet

I did both, Mike. I don't think an answer that advises trying something unrelated to the problem is productive.

ruby on rails - Capybara, Javascript and RSpec Integration Tests with ...

ruby-on-rails rspec capybara integration-testing
Rectangle 27 0

Use <%= form_tag(url, :remote => true) do %> to make the call with Ajax, so your page will not be redirected. Use your server logs to see if the request is executed (if you want to get the result of the ajax call in your page, look at http://www.alfajango.com/blog/rails-3-remote-links-and-forms/).

ruby on rails 3 - saving file after passing parameter - Stack Overflow

ruby-on-rails-3 string file-io save
Rectangle 27 0

Plain :remote => true makes a request that accepts application/javascript, */* (or something similar). But your controller does not respond to javascript, so it tries to render html template.

json
= form_for [@list, @item], :remote => true, :html => {:class => 'form-inline', 'data-type' => 'json'} do |f|

Thanks Dimuch, i wasn't sure what was happening there and understanding that the controller was trying to render HTML helped me hone in on the solution. I've posted an update above. Just required some changes to the controller code to at least get the alert working.

ruby on rails - form returned from AJAX request is not recognized as '...

ruby-on-rails ajax ruby-on-rails-3 ujs
Rectangle 27 0

<%= form_tag(channel_get_dates_path(@channel, :write => 1), :remote => true) do %>
     <input type="submit" value="Get Today's Date">
     <input type="text" value="<%=@write_date%>">
  <% end %>

after this when i press the submit button the update method is called(and i can see that device is sending the date), but the date is not displaying in text field. when i refresh the page the last obtained date from device is displayed in text field. Is it possible to display the date every time when press submit button?

ruby on rails update page with ajax - Stack Overflow

ruby-on-rails ruby ajax model-view-controller dynamic
Rectangle 27 0

If you want to refresh the page after it, you can just point this button to some action at your controller and then redirect_to :back. :remote => true causes the page to send an AJAX request and it will not reload the page.

Or just don't set :remote => true, if the page is going to refresh anyway.

yes, but how do I use button_to to update objects B (juste change an integer) ?

Well the button will just get you started, you'll need to set up the routing, a controller action, etc. The button just gets the party started, and button_to is just a view helper that renders some html for you.

ruby on rails - Button_to : update database - Stack Overflow

ruby-on-rails ruby-on-rails-3
Rectangle 27 0

url_for doesn't accept the :remote => true argument, it's usually the link_to method that you would send it to.

Is there a reason you can't make your <div> a link instead? For all intents and purposes it is functioning as a link, so you should mark it up as such, we call that semantic mark-up.

If you really wanted to do this it would probably be best to use jquery (or prototype, if that's your cup of tea) to perform the action unobtrusively... it makes it easier to do the ajax request too. Are you trying to update something on your page after the link is clicked, or just do nothing?

Also the 'window.location' is telling the javascript on the page to redirect. You wouldn't use that if you wanted to make the request remotely.

Using jquery you could do it like this if you want to stick with a div

%(function(){
  $('#foo').click(function(){
    $.get(
      url: $(this).data('request-path'),
      success: function(data){
        alert('success sir!  controller responded with ' + data);
      }
    );
  });
});

And use this in your view:

<div id='foo' data-request-path='<%= url_for foo_controller_path(:someparam => @left) %>'></div>

But if you changed it to a link tag you could do this instead...

= link_to("", url_for(foo_controller_path(:someparam => @left)), :remote => true, :id => 'foo')

And it ought to just work. Then you can style this link the way that you were trying to style your div tag.

This is more semantic and less code for you to worry about. If you need to update something in the dom afterwards you can add this jquery (if you're using jquery, and rails3):

$('#foo').bind('ajax:success', function(data){
  alert('successful request!  data was:  ' + data);
});

I didn't necessarily test all of this but it should be a good starting point... I'm not a big fan of putting onclick handlers into tags. It tends to work nicer when you bind events using jquery.

If you want to be able to do what i've described but you're in rails 2, you can get the rails3 jquery script from here: https://github.com/rails/jquery-ujs

Note that you'll also need that script if you're using rails 3 and want jquery instead of prototype (like me!). Rails 3.1 will come bundled with jquery instead of prototype I hear, by default.

And change the :remote => true in that url_for to "data-remote" => true (for rails 2, with rails 3 you can use the symbol syntax and it makes the 'data-remote' attribute for you.

Let me know if something didn't quite work or you need clarification. Or even if you hate my ideas alltogether :p

That does the trick, I will use the UJS with jquery you recommended. Unfortunately I do have to make the div clickable as it doesn't actually contain anything other than a vector image that is drawn using javascript.

ruby on rails - :remote => true with url_for, How does one do this? - ...

ruby-on-rails
Rectangle 27 0

The :remote => true option is a bit weird if you aren't returning JSON data. You can wrap your HTML in a JSON object, though, which is what I typically do. Or if you want something closer to your existing code something like this should work for you:

<%= link_to "Refresh Seats", "/flights/#{@flight.id}/seats", :class => "refresh-seats" %>
$(document).delegate(".refresh-seats", "click", function(e){
  e.preventDefault();
  $("#seats").load(this.href);
});

That works great! Thanks for the example code. There was one minor flaw though. ;) You forgot the # before seats in your selector. Thanks for the help....i've been learning that there is a lot that has changed with Rails 3+.

jquery - Ruby on Rails 3: AJAX call not refreshing div with link_to - ...

ruby-on-rails jquery link-to
Rectangle 27 0

I figured out how to send and display html. From theReq, just add :remote => true, "data-type" => "html" to the form and then in the javascript of the page, capture the returned html on ajaxSuccess to display it:

$('form#whatever').on('ajaxSuccess', function (event, data, status, xhr) {
    $('div#target').html(data);
  }
)

ruby on rails - where does render :partial html end up - Stack Overflo...

ruby-on-rails ajax model-view-controller partial-views renderpartial
Rectangle 27 0

I think this has to do with respond to xhr in the controller. you should specify this is a xhr request. See here for a question on that.

That's what :remote => true does; the issue is on the client side.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

ruby on rails - form_tag with :remote => true does not update div, ski...

ruby-on-rails ajax ruby-on-rails-3 forms
Rectangle 27 0

You can do using javascipt events in page or with :remote => true, you can return Javascript. Check this useful cast ;)

Changing a div after a form submission using ruby on rails and ajax - ...

ruby-on-rails ajax
Rectangle 27 0

<%= link_to "Show all depts", model_path(), :remote => true %>

then your request will be sent as ajax. create a view for js with

<div>some code</div>
<%= render :partial => 'index.html' %>
$('#debts_div).replaceWith('<%= j( render :partial => 'index', :format => :html ) %>');

that should work

Great! It works. Thank you! One more question: now I have in index.html.erb file @opened_debts which opened by default and in index.js.erb file @all_debts. How I can reload @opened_debts again via ajax? How I can trigger via link what variable i want to render? Thanks!

create a partial _index.html and you could use it with index.html.erb and also inside index.js.erb. I've extended the answer. see below

ruby on rails - Update page with AJAX on link click - Stack Overflow

ruby-on-rails ajax ruby-on-rails-4
Rectangle 27 -1

The problem is happening with the capybara-webkit driver and works correctly in Chrome.

well that was a suggestion,you could have commented on my answer rather than giving negative marking @carolclarinet

I did both, Mike. I don't think an answer that advises trying something unrelated to the problem is productive.

ruby on rails - Capybara, Javascript and RSpec Integration Tests with ...

ruby-on-rails rspec capybara integration-testing