Hi
I am having trouble with a submit code for a form. I don’t get errors
or anything. it just goes to the redirect and it dosen’t show anything
def create
@comment = ForumComment.new(params[:post])
@comment.user_id = current_user.id
if @comment.save
redirect_to :controller => ‘forums’, :action => ‘index’
end
redirect_to :action => ‘create’
end
end
the create.rhtml just has this code for error reporting(to help me fix
it)
<%= error_messages_for ‘forum_comment’ %>
is there anything wrong with the create method syntax?
thanks in advaced
You probably meant that second redirect to be a render. Your code
would fail if the save actually happened since you would then both
render and redirect.
Typically the pattern is
def new
@foo = Foo.new
end
def create
@foo = Foo.new(params[:foo])
if @foo.save
redirect_to :controller => ‘somewhere’
else
render :action = ‘new’
end
end
Fred
On 31 Oct 2007, at 16:40, [email protected] wrote:
why do you do the @foo=Foo.new twice? I understand the second once,
since you are doing the create and using the params to receive it, but
isn’t the other one not needed?
The first one is for the new page, which still needs an instance of
foo to render the form (so everything will be blank). You could also
set defaults.
Fred
why do you do the @foo=Foo.new twice? I understand the second once,
since you are doing the create and using the params to receive it, but
isn’t the other one not needed?
thanks,
andres
On Oct 30, 4:33 pm, Frederick C. [email protected]