Rails 3.2.2 Not Executing Rjs

Rails 3.2.2 not executing rjs

It looks like rjs has been removed as the default as of Rails 3.1. You could get it back by installing the prototype-rails gem, but I think you should just use jQuery, which is the new default.

As for your code, the reason it's not working is that it's an rjs template being interpreted as .js.erb, and this is likely just producing invalid JavaScript (you should see errors in the JavaScript console in your browser). An rjs template used to set the page variable for you, and you would write Ruby code using it to manipulate your page. In a .js.erb template, it works more like in your .html.erb views. You write actual JavaScript, with Ruby embedded using <% %> tags. So the code in create.js.erb should look something like this:

 alert('NO PROBLEM HERE');
$('#cart').html("<%= escape_javascript(render(@cart)) %>");

(Rails,Javascript) RJS Can't find variable error not providing detailed information

Wow. Nevermind. Was a case of attempting to follow an example too closely. Literalism FAIL! After adjusting my ":with" to "point = #{domid}" everything worked.

Rails 3 remote link displays RJS code on page

please include csrf_meta_tag helper in the header..

RJS method outputting raw javascript

Since your remove function doesn't seem to actually delete a record, if you just want to remove an HTML element from a page you can use link_to_function with the Prototype remove() method for Elements. In addition, if you've got a recent version of Rails (for example, 2.3.2) you can take advantage of the dom_id helper to auto generate the sentance_id ID attribute

<%= link_to_function(image_tag("button_delete.gif", :alt=>"Delete"), "$('#{dom_id(@sentence}').remove();" %>

An approach like this could help keep the number of methods down in your controller (unless you intend on doing something else in the controller)

How to reload partial pages in Rails using RJS?

The code will look like:

  page.replace_html "login-block-id", :partial => "users/login"

Where login-block-id is the id of element that wraps your login template

Note that replace_html can accept the same arguments as render do.



Related Topics



Leave a reply



Submit