2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Ruby on Rails] [form_tag] [Routing Error]について

Last updated at Posted at 2018-06-28

Ruby on Railsでform_tagのRouting Errorで質問です。

環境
・cloud9

前提条件
・rails 5.1.4

フォームで値を取得して、
それに合致するurlへparamsで送ろうとしてます。
ただ、
Routing Error
No route matches [GET] "/post"
となってしまい改善されません。
改善策としてはroutesの記述する順番を入れ替えました。
お分かりになる方ご指摘お願いいたします。

top.html.erb
<%= form_tag("/post/#{params[:id]}", method: "get") do %>
  <%= text_field_tag(:id) %>
  <%= submit_tag("Search") %>
<% end %>
post_controller.rb
  def show
   @city = City.find_by(id: params[:id])
   @id = params[:id]
  end
routes.rb
Rails.application.routes.draw do

  get "post/:id" => "post#show"
  get "/" => 'home#top'
2
1
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?