I have a form for a nested resource (Client :has_many Workouts) that I want to pre-populate based on some user input (I use this input to set up some other default parameters for the new action).
<% form_tag new_client_workout_path(@workout_user) do%>
<%= date_select nil, :date %>
<%= submit_tag 'Enter New Workout' %><br/>
<% end %>
If I submit this form I get the following error.
ActionController::MethodNotAllowed Only get, put, and delete requests are allowed.
I can update the form’s method to get, which works, but then I have all of my form paramters on the query string which I don’t want.
Is there some way to accomplish this using a post?
I’ve done something similar when the resource wasn’t nested and it worked fine.
So, as I understand it, you want a form (as shown) to be sent as a POST to a controller which causes another form to be rendered which is pre-populated with date-directed parameters (from the first form), right?
It’s unconventional but you could just change the
newaction of yourWorkoutsControllerso accept a POST instead of the conventional GET. Inroutes.rbUPDATE
The clean RESTful way to do something like this is to have a separate controller (working title –
ConfigWorkoutsContoller) and actions (newandcreate) for the first form as follows;ConfigWorkoutsContoller#newrenders the form (as shown) which is a GETcreateaction with thedateConfigWorkoutsContoller#createpre-populates a @workout instance and rendersWorkoutsController#new