1

我在rails 中有一个修改ActiveRecord 的页面。自然,如果用户重新加载页面,我们将尝试重复修改,但失败了。我想重定向用户将“重新加载”的 URL(使用浏览器的“重新加载当前页面”按钮)。我想使用相同的控制器、相同的 ID、不同的操作(不是“更新”而是“编辑”)重新加载谢谢。

添加了更新方法

  # PUT /machines/<uuid> - a catch-all path for machine and channel modifications

  def update

    puts "machines:update #{params.to_s}" if @@debug_machines
    @id = params[:id]
    @machine = Machine.find_by_uuid(@id)

    puts "machines:update #{@machine.to_s_full}" if @@debug_machines

    session[:machine_id] = @id

    if params[:delete_channel]
      first = params[:delete_channel].keys.first.to_i
      puts "machines:update delete_channel #{first.to_s}" if @@debug_machines
      last = @machine.last_light_index(first)
      if last
        last.downto(first) do |i|
          @machine.channels.delete(@machine.channels[i])
        end
      else
        @machine.channels.delete(@machine.channels[first])if @machine.channels[first]
      end

    elsif params[:delete_filter]
      i = params[:delete_filter].keys.first.to_i
      puts "machines:update delete_filter  #{i.to_s}" if @@debug_machines
      channel = @machine.channels[i]
      puts "machines:update delete_filter  #{channel.to_s}" if @@debug_machines
      @machine.channels.delete(channels) if channel

    elsif params[:add_filter]
      i = @machine.last_light_index(params[:add_filter].keys.first.to_i)
      puts "machines:update add_filter channel #{i.to_s}" if @@debug_machines
      light = @machine.channels[i].light
      puts "machines:update add_filter light #{light.to_s}" if @@debug_machines
      @machine.channels.insert(i + 1, Channel.new(:light => light))


    elsif params[:commit]

... lots more similar stuff here ...

    end

    puts "machines:update after update #{@machine.to_s_full}" if @@debug_machines

    render :action => :edit
  end
4

1 回答 1

2

It's as simple as

redirect_to :action => :edit
于 2012-04-13T20:37:59.323 回答