Code Monkey home page Code Monkey logo

Comments (4)

zw963 avatar zw963 commented on September 27, 2024

Is there any info that needs to be update for clarify?

from lucky.

matthewmcgarvey avatar matthewmcgarvey commented on September 27, 2024

redirect_back is working as expected. When you went to the edit page from the universities index page, the index was the referrer. But when you submit the form, the referrer is the get request for the edit page which is why it sent you back to it. I would recommend passing the url you want to send them back to as a field in the form if that's what you really want. Otherwise, just always redirect to the index

(Of course, I could be wrong).

from lucky.

zw963 avatar zw963 commented on September 27, 2024

This issue has been going on for some time, please let me try to reexplain it with more details.

  1. When i visit GET /universities/788/edit from the index page ("http://127.0.0.1:3000/universities"), I add some pp! code in the edit page, as following, the output of context.request.headers["Referer"] and previous_url(Universities::Index) in the form page both correct.

both output in the edit form page

web | context.request.headers["Referer"] # => "http://127.0.0.1:3000/universities"
web | previous_url(Universities::Index) # => "http://127.0.0.1:3000/universities"

  1. Let me submit the form

Then submit the form use PUT action, as you said in the reply, action print referer as edit page correctly

output in the action

request.headers["Referer"] # => "http://127.0.0.1:3000/universities/788/edit"

  1. We save the form successfully, the code is jump into the following redirect_back as following.
      if operation.saved?
        pp! "Print in update action", request.headers["Referer"]
        flash.success = "修改成功"
>        redirect_back fallback: Index, allow_external: true
      else
        flash.failure = "出错了"
        html EditPage, operation: operation, university: updated_university
      end
  1. Then the following output is the pp! in the edit page. (redirect_back redirect page back to original edit page in this case)
web          | GET /universities/812/edit
web          |  ▸ Handled by Universities::Edit
web          | "Print in form" # => "Print in form"
web          | context.request.headers["Referer"] # => "http://127.0.0.1:3000/universities/812/edit"
web          | previous_url(Universities::Index) # => "/universities"
web          |  ▸ Rendered Universities::EditPage
web          |  ▸ Sent 200 OK (3.11ms)
  1. so, the issue is, why previous_url(Universities::Index) return "/universities"? as the expected behavior said in your reply of redirect_back, previous_url should return edit page, right?

@matthewmcgarvey Thanks.

from lucky.

jwoertink avatar jwoertink commented on September 27, 2024

My guess is maybe a bug in previous_url ?

I'm not sure what this line is doing

return fallback.path if request.resource == referrer_path

from lucky.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.