# Create post method error

**URL:** <https://www.ruby-forum.com/t/create-post-method-error/118787>\
**Category:** Rails\
**Created:** [October 30, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/create-post-method-error/118787 "2007-10-30T23:05:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@JoeRails](https://www.ruby-forum.com/u/JoeRails)\
**Post date:** [October 30, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/create-post-method-error/118787/1 "2007-10-30T23:05:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JoeRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@JoeRails](https://www.ruby-forum.com/u/JoeRails)\
**Post date:** [October 31, 2007, 12:34am UTC](https://www.ruby-forum.com/t/create-post-method-error/118787/2 "2007-10-31T00:34:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JoeRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@JoeRails](https://www.ruby-forum.com/u/JoeRails)\
**Post date:** [October 31, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/create-post-method-error/118787/3 "2007-10-31T18:11:32Z")

</div>

On 31 Oct 2007, at 16:40, removed\_email\_address@domain.invalid 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

---

<div class="post-metadata">

**Author:** ![JoeRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@JoeRails](https://www.ruby-forum.com/u/JoeRails)\
**Post date:** [October 31, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/create-post-method-error/118787/4 "2007-10-31T17:41:05Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
