https://select2.org/getting-started/basic-usage
我想像上面链接中的第一个示例一样搜索帖子标题。
代码:
<!-- search -->
<div class="card my-auto">
<%= form_with url: posts_path, method: :get, local: :true do |f| %>
<div class="card-body">
<p>Search for a Post title.</p>
<%= f.collection_select(:post_id, Post.all, :id, :title, {include_blank: 'Post titles'}, {class:'selectbooktitle form-control'}) %>
<hr>
<div class="input-group">
<span class="input-group-btn">
<%= f.submit 'Search', class: 'btn btn-outline-success'%>
</span>
<% end %>
</div>
</div>
</div>
这是单击提交时来自我的服务器的请求。
Started GET "/posts?utf8=%E2%9C%93&post_id=16&commit=Search" for 127.0.0.1 at 2018-05-09 14:18:51 +0200
Processing by PostsController#index as HTML
Parameters: {"utf8"=>"✓", "post_id"=>"16", "commit"=>"Search"}
Rendering posts/index.html.erb within layouts/application
Post Load (0.3ms) SELECT "posts".* FROM "posts"
Post Load (0.3ms) SELECT "posts".* FROM "posts" ORDER BY created_at DESC
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 4], ["LIMIT", 1]]
Rendered posts/index.html.erb within layouts/application (10.2ms)
Category Load (0.3ms) SELECT "categories".* FROM "categories"
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
Rendered layouts/_navbar.html.erb (4.5ms)
Rendered layouts/_alerts.html.erb (0.4ms)
Rendered layouts/_footer.html.erb (0.6ms)
Completed 200 OK in 59ms (Views: 55.0ms | ActiveRecord: 1.9ms)
指向此 URL:
http://localhost:3000/posts?utf8=%E2%9C%93&post_id=20&commit=Search
它应该指向以下 URL:
http://localhost:3000/posts/20
我究竟做错了什么?
预先感谢您的任何帮助!