Understanding Ruby on Rails Routing Errors

Asked 2 years ago, Updated 2 years ago, 33 views

Routing Error
No route matches [POST]"/"
It came out and got stuck.

What to do.
There is an input window on the front page to register the beta email address in form_for, and if you submit the email address in it, it will be saved in the database, but I cannot proceed due to a routing error.
The following controllers

class RootController <ApplicationController
  def index
    @articles=Article.all
  end

  def new
    @guest=UserInvitationBetarelease.new
  end

  def create
    @guest=UserInvitationBetarelease.new(guest_params)
    @guest.save
    redirect_to root_index_path
  end

  private

  default_params
    param.require(:guest).permit(:email)
  end
end
  • View below

    = form_for : guest do | f |
    = f.text_field:email
    = f.submit "Send"

View

= form_for : guest do | f |
= f.text_field:email
= f.submit "Send"

The root file is as follows
resources:root

I would appreciate it if you could let me know

ruby-on-rails ruby

2022-09-29 22:02

1 Answers

Error due to accessing POST/ is not defined.
You can use the rake command below to see which routes are currently defined.
How about comparing the results of this command with the config/routes.rb configuration and action attributes of the form?

bin/rake routes

resources:if root...

#config/routes.rb

resources:root

It should be defined from /root as follows:

$bin/rake routes
    Prefix Verb URI Pattern Controller # Action
root_index GET/root(.:format) root#index
           POST/root(.:format) root#create
  new_root GET/root/new(.:format)root#new
 edit_root GET/root/:id/edit(.:format)root#edit
      root GET /root /:id(.:format)root#show
           PATCH/root/:id(.:format)root#update
           PUT/root/:id(.:format)root#update
           DELETE/root/:id(.:format)root#destroy

Isn't the action URL of the form tag wrong?

Also, I haven't looked into it strictly, but the resource name and controller name are likely to fall under the reserved word, so I think it's not very good.I recommend that you change it.


2022-09-29 22:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.