ruby-on-rails - Ruby on Rails - redirect_to does not redirect, yet creates successful GET request
问题描述
Rails 6.1.2.1
Ruby 2.7.2p137
Whenever I use the redirect_to
helper in my rails app, I am not redirected to a new page. However a successful GET request is made in the browser to the correct path and the response to that request contains the markup for that page. This is very confusing to me, as I'd normally expect that to be all there is to it. I have tried this in Firefox and Chrome, with an without addons.
To further clarify, the rails server is responding correctly with a redirect to the right page, but the browser does not show that page.
Here is an example controller action that includes the redirect.
def create
properties =
allowed_location_params.merge(universe_id: params[:universe_id])
@location = Location.create!(properties)
flash[:success] = "Location created!"
redirect_to location_url(@location)
end
Here is the form that invokes the above action.
<h1>New Location</h1>
<%= form_with model: @location, url: universe_locations_url(universe_id: @location.universe_id) do |form| %>
<div class="mb-3">
<%= form.label :name, class: "form-label" %>
<%= form.text_field :name, class: "form-control" %>
</div>
<div class="mb-3">
<%= form.label :description, class: "form-label" %>
<%= form.text_area :description, size: "60x10", class: "form-control" %>
</div>
<%= form.submit "Save", class: "btn btn-primary" %>
<% end %>
It is my assumption that upon submitting the form here, I should be redirected to the show view for the new Location I just made. Instead I get a GET request in the networking tab, it returns with status 200, the response includes the correct page, and then nothing. The user is not redirected to that page.
Any idea what I'm doing wrong?
解决方案
推荐阅读
- javascript - Discord.js 等待 net.Socket 连接
- node.js - 如何在 node.js 中使用面向对象的设计模式实现中间件?
- python - 试图从 html 的下拉列表中获取一个值,并使用该值作为键来查询数据库并在 django 的同一页面上显示结果
- outlook - Outlook 应用程序没有 getItemIdAsync 功能,但 Web Outlook 在为约会创建 Web 插件时具有
- flutter - Flutter 错误 - 断言失败:第 298 行 pos 10:'data != null':必须向 Text 小部件提供非空字符串。登录时
- powershell - 如何使用列表选项和 JMESPath (az-cli) 检测资源是否存在?
- python - Python Flask,我并不总是从复选框中获取完整数据
- android - 如何监听 SwitchPreferenceCompat 的变化
- django - 来自同一模型的两个或多个唯一外键(依赖链)
- jquery - 对多个页面使用单个 JQuery 文件导致“未捕获的类型错误”