I have a really basic Rails 7 application at the moment. Using all the defaults.
For some reason, Rails is not entering/running the code within a controller I've defined.
Here is the related route.
scope module: 'admin', path: 'admin', as: 'admin' do
root 'home#index'
resources :users do
post :invite, on: :collection
end
end
Here is the related Controller method:
def invite
puts "INVITE" * 100
invite_params = params.require(:admin_invite).permit(:name, :email)
@invite = Admin::Invite.new(invite_params)
respond_to do |f|
if @invite.send_invite
f.html { redirect_to admin_users_url, notice: "Invite sent" }
else
f.html { redirect_to admin_users_url, status: :unprocessible_entity, error: "There was an error sending the invite" }
end
end
end
Here is the form that POSTs to that route.
= form_with model: @new_invite, url: invite_admin_users_url, html: {"data-turbo" => false} do |f|
= f.label :name
= f.text_field :name
= f.label :email
= f.email_field :email
= f.submit "Invite"
I thought maybe it had something to do with TURBO that comes with Rails 7, so I disabled it on this form, but it didn't resolve the issue.
When I click submit on that form, I get the following error: No template found.
Looking at the output in the terminal, it seems to be POSTing properly to the controller, but it's not running any of the code with the method. Even that puts statement I have at the beginning of the #invite method doesn't execute.
19:26:14 web.1 | Started POST "/admin/invite_user" for ::1 at 2022-09-07 19:26:14 -0400
19:26:14 web.1 | Processing by Admin::UsersController#invite as HTML
19:26:14 web.1 | Parameters: {"authenticity_token"=>"[FILTERED]", "admin_invite"=>{"name"=>"Test", "email"=>"test@test.com"}, "commit"=>"Invite"}
19:26:14 web.1 | User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
19:26:14 web.1 | No template found for Admin::UsersController#invite, rendering head :no_content
Any ideas?