I have a GET route which, before rendering the view, the Controller checks for an optional param. If it's there, I'd like to bypass rendering the view and "redirect" straight to another controller action. The other action is a PUT route and I realize we can't simply redirect to PUT routes as you could to a GET route.
This is roughly what I've attempted so far but I don't know how to invoke the redirect, as it's impossible with PUT. Perhaps there's some different design pattern for handling this sort of behavior? Thanks in advance.
Controller actions:
def foo
if 'XYZ'
# "redirect" to bar
else
render 'view'
end
end
#bar is a PUT route
def bar
...
end
If you have your routes for bar
action something like this
match '/controller/bar/' => 'controller#bar'
modify it like
match '/controller/bar/' => 'controller#bar' , :via => [:get,:post,:put]
If you just want to use the bar
method given the condition being met
def foo
if 'XYZ'
bar
else
render 'view'
end
end
This would run the bar
method and make use of any redirect you have in there. It is more likely that you want to reexamine what it is you are trying to achieve.
If you can give more specifics then you will get a better answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.