I read in another answer that it's bad practice to redirect_to
a different controller's create
action.
I'm trying to implement a Create Foo and Bar
button in my form on Foos#new
.
Foo
uses the information from the form and Bar
can use Foo
's id to Foo.find(params[:foo_id])
to get the information from Foo
it needs. It makes sense to me that I should do something like:
if params['route_to']['bar']
redirect_to controller: :bars, action: :create, foo_id: @foo.id
else
redirect_to foos_path
end
at the end of my Foos#create
.
- Am I making an architectural mistake?
- What is a better way?
- How do I tell
redirect_to
toPOST
instead ofGET
? Because right now I'm submitting aGET
when I want aPOST
- Should I use concerns?