Home>

There is a chapter in the reference book "Introduction to ruby ​​on rails5" that creates a form for the user to input data.
So I got the following error and I don't know why ...

I want to access http: // localhost: 3000/helo/index so that the page is displayed correctly.

Error message

Routing Error
No route matches [GET]"/helo/index"
Rails.root: c:/Users/user/Desktop/RailsApp

Application Trace | Framework Trace | Full Trace
Routes
Routes match in priority from top to bottom
/ * Path below */
helo_path POST /helo(.:format)
helo # index

helo_index_path POST /helo/index(.:format)
helo # index

rails_service_blob_path GET /rails/active_storage/blobs/:signed_id/*filename(.:format)
active_storage/blobs # show

rails_blob_representation_path GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format)
active_storage/representations # show

rails_disk_service_path GET /rails/active_storage/disk/:encoded_key/*filename(.:format)
active_storage/disk # show

update_rails_disk_service_path PUT /rails/active_storage/disk/:encoded_token(.:format)
active_storage/disk # update

rails_direct_uploads_path POST /rails/active_storage/direct_uploads(.:format)
active_storage/direct_uploads # create

Applicable source code

RailsApp \ app \ views \ helo \ index.html.erb
<h1><% = @title%></h1>
<p><% = @msg%></p>
<form method ="POST"action ="/helo/index">
<input type ="text"name ="input1"value ="<% = @value%>">
<input type ="submit">
</form>
RailsApp \ app \ controllers
def index
if request.post? then
@title ='Result'
@msg ='you typed:'+ params ['input1'] +'.'
@value = params ['input1']
else
@title ='Index'
@msg ='type text ...'
@value =''
end
end
end
RailsApp \ config \ routes.rb
post'helo&apos ;, to:'helo # index'
post'helo/index'

Tried

(1) I checked the routing settings when trying to access via POST, but I did not understand well. (Access with GET is to access by entering URL as usual? How to enter POST?)

② I have downloaded the sample of the reference book help site, but the same error occurred.

Supplemental information (FW/tool version etc.)

Ruby ver: 2.4.4.2

  • Answer # 1

    Hello

    Communication to/helo/indexas the destination of the form is a post request, but the display of this page itself is to/helo/indexget request
    Therefore, it is necessary to add a get request to/helo/indexinconfig/route.rb