下記のコードは追加したものをindexに表示するというものです
Scaafoldで作ってeditとdestroyを消しました
そしてindex.htmlに検索バーをつけようと思い、こういう風に書きました
Ruby
1<p id="notice"><%= notice %></p> 2 3<h1>Title</h1> 4<%= form_tag action: :search do %> 5 <%= label_tag :title, 'キーワード:' %> 6 <%= text_field_tag :title %> 7 8 <%= submit_tag '検索' %> 9<% end %> 10 11<table> 12 <tbody> 13 <% @projects.each do |project| %> 14 <tr> 15 <td><%= project.title %></td> 16 17 <td><%= link_to 'Show', project %></td> 18 </tr> 19 <% end %> 20 </tbody> 21</table> 22 23<br> 24 25<%= link_to 'New Project', new_project_path %>
コントローラは
Ruby
1class ProjectsController < ApplicationController 2 before_action :set_project, only: [:show] 3 4 5 def index 6 @projects = Project.all 7 end 8 9 10 def show 11 end 12 13 # GET /projects/new 14 def new 15 @project = Project.new 16 end 17 18 19 20 # POST /projects 21 # POST /projects.json 22 def create 23 @project = Project.new(project_params) 24 25 respond_to do |format| 26 if @project.save 27 format.html { redirect_to @project, notice: 'Project was successfully created.' } 28 format.json { render :show, status: :created, location: @project } 29 else 30 format.html { render :new } 31 format.json { render json: @project.errors, status: :unprocessable_entity } 32 end 33 end 34 end 35 36 37 def search 38 @projects = Project.where('publish = ?', params[:title]) 39 render 'projects/index' 40 end 41 42 43 private 44 # Use callbacks to share common setup or constraints between actions. 45 def set_project 46 @project = Project.find(params[:id]) 47 end 48 49 # Never trust parameters from the scary internet, only allow the white list through. 50 def project_params 51 params.require(:project).permit(:title, :about, :image, :image_cache, :remove_image) 52 end 53end 54
No route matches {:action=>"search", :controller=>"projects"}
といった内容のエラーが出ます
どうすればエラーは消えますか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/12/18 08:41
退会済みユーザー
2016/12/18 09:00
退会済みユーザー
2016/12/18 09:04
退会済みユーザー
2016/12/18 09:11
退会済みユーザー
2016/12/19 01:07
退会済みユーザー
2016/12/19 01:09