Timid Developer
Timid Developer

Reputation: 143

How to set the action with form_for?

I created a new page on an existing controller.

I added 2 action methods on the controller: prompt_user and process_feedback.

So I get to the page via

redirect_to :controller => :users, :action => :prompt_user

And the form_for code looks like

<% form_for :user, @user do |f| %>

Which generates the following html

<form action="users/prompt_user" method="post">

Notice the action is prompt_user, where as I want to set it to process_feedback. I thought I could change the action with a button

<%= submit_tag "Process feedback" %>

But that didn't work.

So my question is how can I change the action to process_feedback?

Also, as you can probably tell, I'm very new to rails, so if I'm doing something especially obtuse, I'd love to find out what it is.

Upvotes: 9

Views: 20222

Answers (2)

juliangonzalez
juliangonzalez

Reputation: 4381

Alternatively the same can be reached using form_tag with the syntax:

See my answer on this question: here https://stackoverflow.com/a/37145293/1248725

Upvotes: 2

jonnii
jonnii

Reputation: 28332

This is from memory, but I think you can do something like this:

form_for :user, @user, :url => { :action => :prompt_user } do |f|

Upvotes: 18

Related Questions