javascript - Rails console shows view is rendered, but doesn't render in browser -
It looks very strange. I have a link that I want to call the controller an AJAX call so that users' responses can be removed, then redirect to another page. Here's the code for the link:
& lt;% = link_to 'try again', reset_score_path, remote: true, controller: "page", verb: "reset_score", category: BTN BTN-Priority TryAgain ", Data: {Confirm: 'This is your score & lt; Strong & gt; Zero & lt; / Strong> Will reset. And reset all of your answers so that you can start afresh Do you want to continue? ', Committed: "Restart", Cancel: "No Thanks", Focus:' none '}, Title: "Try again?" & Gt%;
And here is the administrator's action:
def reset_score current_user.responses.destroy_all current_user.certificate.destroy redirect_to Action: "course_page1", format: " Html "and end of return
But the problem is that nothing happens in the browser; It does not redirect but the console shows that it is processing visualization and rendering. See console output:
127.0.0.1 for "/ pages / reset_score" has been started 2014-10-17 07:19:45 -0500 Processing by PageSeter # reset_score JS User Load Select "Reactions" by "Users" by the "ID" = 62 Order "AD" = 62 Order "AD" ASC limit 1 Response Load (0.3 MMS) by "Users." Where "Reactions". "User_id" =? [["User_id", 62]] [AWS S3404 0.306706 0 Comments] Head_Object (: Batti_name = & gt; "...",: key = & gt; "x.pdf") LS :: S3 :: Errors :: NoSuchKey No Such Key Returned to http: // localhost: 3000 / pages / course_page1.html 315ms (ActiveRecord: 0.6ms) 302 found in 2014-10-17 of 127.0.0.1 For "/pages/course_page1.html" received 07:19:45 -0500 PagesController # course_page1 Select "user" as HTML user load (0.2 ms). * Where "user" from "user" "ID" = 62 Order "Users" "ID" ASC LIMIT 1 Rendered Pages / Courses_page 1.html. ARB Layout / Applications Rated layout within (0.3 mms) / _header.html.erb (0.4ms) full 200 OK 80ms (view: 78.5 ms. ActiveCrack: 0.2 mms)
So it looks like the scene has been presented. Although the browser does not really show this view - it only stays on the previous page.
Any thoughts?
(Yes, I know that the AWS is giving an error, but I do not consider it related to this problem?)
Edit : Pamio Thanks for the reply, this is the solution code for the controller (instead of the above line 4):
def reset_score current_user.responses.destroy_all current_user.certificate.destroy response_to do | Format | Format.js {Render: JS = & gt; "Window.location.href = '# {pages_course_page1_path}'"} End End
You used the redirect_to verb: "course_page1", format: "html" and return
that are not correct. Redirect will work fine if it was an HTML request but was not Ajax. So if you want to redirect despite the fact that the request was an Ajax, its use could be something like this
format.js {render: js = & gt; "Window.location.href = '# {course_page_path}'}}
Or remove the remote: true
attribute from the link so that it works just fine.
Hopes
Comments
Post a Comment