在我的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
变量,我该如何解决?
答案 0 :(得分:4)
redirect_to show_fail_path(:title =&gt; @ post.title)
从params [:title]
中取出