0

我对 Ruby 很陌生,可能做错了,但是如何在没有路由的情况下进行控制器操作?

我需要这个控制器仅用于从另一个控制器重定向。见下文

  def redirect_to_correct_stage
case @lession_stats.stage
  when 'stage1'
    puts "Redirecting to stage1"
    redirect_to :action => :stage1
    return
  when 'stage2'
    puts "Redirecting to stage2"
    redirect_to :action => :stage2
    return
  when 'stage3'
    puts "Redirecting to stage3"
    redirect_to :action => :stage3
    return
  else
    redirect_to root_path, :alert => t(:error_unknown_stage)
end

结尾

我的主要操作是 redirect_to_correct_stage 并具有正确的路径('/word'),我需要根据模型值将其重定向到正确的操作。

一切正常,但现在人们可以使用 ('/stage3') 直接移动到 stage3 当然我可以在 stage3 操作中添加更多检查,但我不想检查两次。

我该怎么办?

4

1 回答 1

2

控制器动作是一种带有路由的方法,是应用程序的入口点。如果您确实添加了没有路由的方法,则无法通过 Web 请求调用它。

于 2013-07-16T13:17:45.023 回答