Checking request.post? before action

I have the following code:

   def create
     redirect_to :action => "index" unless request.post?
     @entry = Entry.new(params[:entry])
     if @entry.save
       flash[:notice] = "Successfully created..."
       redirect_to :action => "index"
     else
       render :action => "new"
     end
   end

I get an error "Can only render or redirect once per action".
I understand "redirect_to" or "render" doesn't end the script.

I would like to allow only "post" request for "create" action,
so I need to do somehting about this.

But how can I improve the script?

Is there any way to write
redirect_to :action => "index" unless request.post?
in model?

Tek

Tek,

You need to return or the processing keeps happening through the
method. I.e.:

redirect_to :action => "index" and return unless request.post?

:slight_smile:

-Danimal