I’m trying to redirect to a custom view from a controller in my rails app. The following works:
redirect_to :action => 'myaction', :id =>@myobj.id
An I have a controller action named myaction
In my routes.rb file I have
match 'myobjs/:id/myaction' => 'myobjs#myaction'
But I would like to use the more concise syntax of
// this is the line I cannot get to work
redirect_to myaction_path
What is the correct syntax for redirecting to a custom view like this?
There is an
:asoption you can pass to thematchmethod.This would create helper methods called
myaction_pathandmyaction_urlyou can use in your controllers and views.The Rails routing guide is here