rails redirect or render with a specific verb
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 => 开发者_JS百科: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.
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.
精彩评论