Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails重定向到编辑路径错误,来自应用程序控制器的值错误_Ruby On Rails - Fatal编程技术网

Ruby on rails Rails重定向到编辑路径错误,来自应用程序控制器的值错误

Ruby on rails Rails重定向到编辑路径错误,来自应用程序控制器的值错误,ruby-on-rails,Ruby On Rails,我有一个Rails应用程序,其中包含以下路线: edit_admin_review GET /admin/reviews/:id/edit(.:format) admin/reviews#edit 我使用此html和控制器查看了用户表单: <%= form_for @user, url: admin_user_path(@user.id), html: {method: :put}, remote: true do

我有一个Rails应用程序,其中包含以下路线:

edit_admin_review GET    /admin/reviews/:id/edit(.:format)                                  admin/reviews#edit
我使用此html和控制器查看了用户表单:

<%= form_for @user, url: admin_user_path(@user.id), html: {method: :put}, remote: true do |f| %> 
  <div class="row">
      <%= f.label "Name" %>
      <%= f.text_field "name" %>
  </div>
  .....
<% end %>
在应用程序控制器中,我有:

  before_action :location

  protected
  def location
    country = cookies[:country] ||= request.location.country
    if country.present?
      country = ISO3166::Country[country]
      @location = country.translations[I18n.locale.to_s] || country.name
    else
      @location = "Malaysia"
    end
  end
出于某种原因,
edit\u admin\u review\u路径(@user.reviews.last.id)
正在重定向到此路径:
url.com/admin/reviews/73/Malaysia
。。。出于某种原因,而不是:id/edit,它将从应用程序控制器获取位置变量并将其添加到链接

当我删除location方法时,它运行良好,并按预期重定向。我知道我可以通过跳过这个动作来解决这个问题,但我不明白的是,如果它与表单本身无关,为什么它会从位置获取值


最好的方法是什么?为什么会这样?

显示更新操作代码please@ArupRakshit刚刚更新了它,但我认为主要的问题是它出错时的重定向。这可能是您如何配置
routes.rb
的问题。你能用它更新你的问题吗?@Dudis我在玩一个测试应用程序。。无法复制它。。似乎您的应用程序特定的bugRenaming@location解决了这个问题,谢谢您的好提示!请随意添加它作为正式答案,以便我可以标记它
  before_action :location

  protected
  def location
    country = cookies[:country] ||= request.location.country
    if country.present?
      country = ISO3166::Country[country]
      @location = country.translations[I18n.locale.to_s] || country.name
    else
      @location = "Malaysia"
    end
  end