Reputation: 2984
I have a view in my rails app that displayes list of test cases. I added a Jquery-enabled link_to
helper, so that form for adding new test case appears on this page:
<%= link_to 'Add test case',
new_case_path(@case, :format => :js),
:remote => true,
:id => 'new_case_link' %>
I added following code to new.js.rb file:
$("<%= escape_javascript
render(:file => 'cases/new.html.erb') %>").insertAfter('#test_cases');
$('#new_case_link').hide();
The problem is, this helper links to new.js.erb file, which opens in a separate page and shows the rendered jquery code from above. How to fix this problem?
Upvotes: 0
Views: 1314
Reputation: 11055
This problem is usually the result of not including the csrf_meta_tag
in your head section of your layout or not updating the rails.js file to work with jquery. It works for prototype out of the box, so you have to replace that with the jquery driver. Did you install this - https://github.com/rails/jquery-ujs ?
Are you getting any javascript errors on the page? Easy way to check is Tools -> Error Console in Firefox.
Check out this link also. It is a good intro to UJS in Rails 3 with JQuery. http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
Upvotes: 1