Elijah Murray
Elijah Murray

Reputation: 2172

Redirecting to Controller not Passing Action

I'm redirecting from one controller to another. The receiving controller, uploads, doesn't have an index action, but has a create action, which I'm trying to use obviously. However when I redirect, I get the following issue

Unknown action The action 'index' could not be found for UploadsController

redirect_to :controller => 'uploads', :action => 'create', flash: {error: "there was an error"}

Upvotes: 0

Views: 49

Answers (2)

Helios de Guerra
Helios de Guerra

Reputation: 3475

Probably because the redirect_to is assuming that its redirecting with a GET request.

Since the index & create actions both go to the same path and depending on the HTTP verb, Rails decides which action to call...

So if the application gets a GET request to /uploads it will render the index action and if it gets a POST it will call the create action.

Furthermore, I don't think you can redirect_to a http POST... Are you sure that's what you want to do?

Upvotes: 1

kddeisz
kddeisz

Reputation: 5182

Try specifying :method => :post in the request. Create actions should only respond to that, unless you're doing fancy things with routes.

Upvotes: 0

Related Questions