1

I'm following the RailsCast video on jQuery and Ajax. I've added the :remote => true line to the link_to. In the video, it says that nothing should happen but the link still goes to the page.

jQuery is being loaded (I'm using it for other things in my Rails app).

I'm trying to link to two different resources (things that I've generated through scaffolds) which might be the problem. I'm not sure.

Let me know if you need to see more code.

EDIT

I had the jquery_ujs line after some previous JS. I've moved it to the top and the remote link now does not go to the page. However, with my new.js.erb file, I can't seem to get the form to appear when the link is clicked.

Link code:

<%= link_to 'New Project', new_project_path, :id => "new-project-link", :remote => true %>

new.js.erb:

$('#new-project-link').hide().after('<%= j render("form") %>');

Also, I'm getting a header status of 304 (Not Modified) instead of a 200. Does that matter at all?

3
  • Do you also have rails.js in your javascript path? Thats where all the ujs methods like remote are defined ...
    – awenkhh
    Commented Nov 11, 2012 at 23:59
  • can you edit your post and add your code for the link? Commented Nov 12, 2012 at 0:00
  • I've edited the post with answers to both of your questions. Thanks! Commented Nov 12, 2012 at 0:31

1 Answer 1

3

Make sure you've include csrf_meta_tags in the head section of your layout:

http://apidock.com/rails/ActionView/Helpers/CsrfHelper/csrf_meta_tags

Also, I'd check that your respond_to block (for js) is set up correctly in the controller action (Projects#new), and also be sure the request is a GET. I think it will be a POST by default per jquery_ujs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.