Ruby on rails 如何将_重定向到(:返回)两次?

Ruby on rails 如何将_重定向到(:返回)两次?,ruby-on-rails,ruby,Ruby On Rails,Ruby,有办法重定向回两次吗?给你: 这是编辑链接的位置: def update if @note.update_attributes(note_params) redirect_to :back, notice: "Note was updated." else render :edit end end 现在,用户更新表单并重定向回第一个显示或索引页面,或者她来自的任何页面 希望这有帮助。 PS:您可能需要对其进行一些清理,并从控制器传递url,并对其进行一些检查。因此,

有办法重定向回两次吗?

给你: 这是编辑链接的位置:

def update
  if @note.update_attributes(note_params)
    redirect_to :back, notice: "Note was updated."
  else
    render :edit
  end
end
现在,用户更新表单并重定向回第一个显示或索引页面,或者她来自的任何页面

希望这有帮助。
PS:您可能需要对其进行一些清理,并从控制器传递url,并对其进行一些检查。因此,您不需要在视图级别定义任何var。在上面的代码中,我只是试图解决这个问题,而不是真正面向设计模式:)

你怎么知道它们来自两次单击前的何处?有什么有用的吗?它们来自四个show pages@Makoto中的一个,因为便笺是多态的,所以当它们单击编辑便笺,然后单击update时,会重定向回便笺编辑表单,但是如果可能的话,我希望他们重定向回show页面:)不@Kimball他们不会处理返回两次的问题,但是感谢您的尝试您不能将引用页面保存在会话状态吗?即使你最终在4个(或更多!)地方复制了代码,它似乎也不会像两次重复一样困扰你。如果用户在同一会话中打开了多个选项卡,该怎么办?正如@Makoto所暗示的,没有办法知道“回来两次”在哪里。不用担心,伙计。很高兴我能帮忙。干杯
<p id="notice"><%= notice %></p>
<% url = "#{request.protocol}#{request.host_with_port}#{request.fullpath}" %>
<%= link_to 'Create New Page and Return Here', edit_page_path(1, :url => Base64.encode64(url) ) %>
<br>
<%= form_for(@page) do |f| %>
  <% if @page.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@page.errors.count, "error") %> prohibited this page from being saved:</h2>    
      <ul>
      <% @page.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>    
  <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :permalink %><br>
    <%= f.text_field :permalink %>
  </div>
    <%= hidden_field_tag :url, params[:url].to_s %>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
 def update
    redirection = nil
    if params[:url].present?
      redirection = Base64.decode64(params[:url].to_s)
    end
    if @page.update(page_params)

      if redirection.present?
        path = redirection
      else
        path = @page
      end
      redirect_to path, notice:  'All Done.'
    else
      render :edit
    end
  end