I have this in my form view:
<%= error_messages_for ‘post’ %>
I’m not using form_for, just a regular form_tag:
<% form_tag :action => ‘save_requirement’ do %>
The error messages do not pop up, any suggestions?
Thanks!
I have this in my form view:
<%= error_messages_for ‘post’ %>
I’m not using form_for, just a regular form_tag:
<% form_tag :action => ‘save_requirement’ do %>
The error messages do not pop up, any suggestions?
Thanks!
On 22 Jul 2008, at 19:45, Justin To wrote:
I have this in my form view:
<%= error_messages_for ‘post’ %>
I’m not using form_for, just a regular form_tag:
<% form_tag :action => ‘save_requirement’ do %>The error messages do not pop up, any suggestions?
is @post an instance of an activerecord object with some errors?
Fred
is @post an instance of an activerecord object with some errors?
Fred
Yes,
controller:
def new_requirement
@post = Post.new
end
def save_requirement
@post = Post.new(params[:post])
if @post.save
redirect_to_index("Thank you for your post!")
else
redirect_to :action => :new_requirement
end
end
Ah! Great David!
Thanks so much, it works!
Hi –
On Tue, 22 Jul 2008, Justin To wrote:
def new_requirement
redirect_to :action => :new_requirement
end
end
In the failure case, you don’t want to redirect; you want to render.
Redirecting triggers a completely new request cycle, with a new
controller instance, and all instance variables are reset to nil. So
@post will be back to being a new Post instance, which will not have
any errors, so no errors will be displayed.
If you render, on the other hand, you’ll just be rendering the
new_requirement template with the existing @post object, which does
have errors.
David
–
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails July 21-24 Edison, NJ
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs