在redirect_to中传递变量

时间:2012-10-19 16:12:26

标签: ruby-on-rails ruby ruby-on-rails-3

在我的Rails应用程序中,routes.rb我有

match "show_fail" => "Posts#show_fail"

posts_controller.rb

def create
  ...
  return redirect_to show_fail_path, :title => @post.title
end

def show_fail
end

show_fail.html.erb

Unsuccessful posting of post title <%= title %>

但是我收到了错误undefined local variable or method 'title'。为什么它不知道title变量,我该如何解决?

1 个答案:

答案 0 :(得分:4)

redirect_to show_fail_path(:title =&gt; @ post.title)

从params [:title]

中取出