Multiple forms on a single page
-
19-09-2019 - |
Question
I've got an app that's in invite-only beta right now. Problem is, I can't get the invite system to work. :(
On my root page there's a login form (which works just fine), and I'm trying to add a "request invite" form on the same page. I started doing it by putting the form for InviteRequest (ActiveRecord) inside a partial, in the "views" folder for "InviteRequest". The app is definitely calling this partial, but I'm getting the following error:
NoMethodError in User_sessions#new
Showing app/views/invite_request/_new.html.erb where line #2 raised:
undefined method `invite_requests_path' for #<ActionView::Base:0x25b3248>
Extracted source (around line #2):
1: <% @invite_request = InviteRequest.new() %>
2: <% form_for @invite_request do |ir| %>
3: <%= ir.label :email %>
4: <%= ir.text_field :email %>
5: <% end %>
I also read through the "Multiple Models in a Form" section of my trusty copy of "Agile Web Development with Rails", about maybe doing this with a "fieldset" tag, but not sure if this is the right approach.
Thx.
Solution
Your form_for @invite_request
is trying to figure out where the results from the form should be posted. It does this by looking at the routes and finding one that matches the resource and action needed. In your case I'm guessing you haven't set up routes for InviteRequest
. You either need to set up routing for InviteRequest
or specify the URL to be posted to in form_for
.
form_for @invite_request, :url => { :controller => 'application', :action => 'request_invite' } do |form|
...