Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 925
Timid Developer Avatar asked Aug 12 '11 18:08

Timid Developer


2 Answers

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

form_for :user, @user, :url => { :action => :prompt_user } do |f|
like image 79
jonnii Avatar answered Nov 01 '22 02:11

jonnii


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

like image 44
juliangonzalez Avatar answered Nov 01 '22 03:11

juliangonzalez