0

I want to redirect to a resource index when a new item is created

Here is a piece of the controller:

def create
    @asset = Asset.new(params[:asset])
    @assets = Asset.all
    respond_to do |format|
      if @asset.save
        format.html { render :action => 'index' } ##########
        format.xml  { render :xml => @asset, :status => :created, :location => @asset }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @asset.errors, :status => :unprocessable_entity }
      end
    end
  end

The line i'm interested is marked ##########

i've tried

  format.html { redirect_to(assets_url) }

and some other stuff

It redirects to the right place and creates the item fine, the problem is that i cant get it to not POST. I need to get it to GET because otherwise it does some horribly screwy things to my view.

jsalonen
  • 29,593
  • 15
  • 91
  • 109
Sheena
  • 15,590
  • 14
  • 75
  • 113

1 Answers1

0

redirect_to :action => :index Or redirect_to assets_url should work for you. Also, index action is always GET request. Do rake routes to see what kind of request happens for each action in your controller.

Syed Aslam
  • 8,707
  • 5
  • 40
  • 54