Paul S.
Paul S.

Reputation: 4502

passing variables in redirect_to

In my Rails application, in routes.rb I have

match "show_fail" => "Posts#show_fail"

In posts_controller.rb:

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

def show_fail
end

In show_fail.html.erb:

Unsuccessful posting of post title <%= title %>

But I got an error undefined local variable or method 'title'. Why does it not know about the title variable, and how can I fix it?

Upvotes: 4

Views: 3207

Answers (1)

VadimAlekseev
VadimAlekseev

Reputation: 2258

redirect_to show_fail_path(:title => @post.title)

and take it from params[:title]

Upvotes: 4

Related Questions