Home>

https://qiita.com/yusuko/items/cff4e46aeafbc3beecf2 The search function was implemented based on the site, but an error occurred. I've been doing it almost the same way as the site, so it came out, so I'm really in trouble. If i know, please give me an answer. (’_’)

Started GET "/ ugblogs/find" for :: 1 at 2019-11-05 16:41:19 +0900
Processing by UgblogsController # show as HTML
  Parameters: {"id" =>"find"}
  Ugblog Load (1.6ms) SELECT "ugblogs". * FROM "ugblogs" WHERE "ugblogs". "Id" =? LIMIT? [["Id", 0], ["LIMIT", 1]]
  ↳ app/controllers/ugblogs_controller.rb: 72
Completed 404 Not Found in 122ms (ActiveRecord: 15.6ms)

ActiveRecord :: RecordNotFound (Couldn't find Ugblog with 'id' = find):
app/controllers/ugblogs_controller.rb: 72: in `set_ugblog '
class UgblogsController</pre>
<pre><code data-language = "model">mount_uploader: img, ImgUploader
    validates: title,: subtitle,: Text,: img, presence: {message: 'is required. '}
    def self.search (search)
        return Ugblog.all unless search
        Ugblog.where (['content LIKE?', "% # {Search}%"])
      end
end
<p>Search</p>
<% = form_tag (search_path,: method =>'get') do%>
  <% = text_field_tag: search%>
  <% = submit_tag 'Search',: name =>nil%>
<% end%>
<ul><% @ ugblogs.each do | post |%>
  <li>
    <% = link_to ugblog.title, post%>
    <% = ugblog.created_at%>
    <% = ugblog.status%>
  </li>
  <% end%>
</ul>
  • Answer # 1

    Parameters: {"id" =>"find"}

    def set_ugblog
      @ugblog = Ugblog.find (params [: id])
    end

    find is a method to get data using id as a search key, but
    The reason is that "find" is being passed as a parameter.

  • Answer # 2

    /ugblogs/find "is interpreted as Parameters: {" id "=>" find "} The reason is that there is no definition in config/routes.rb

Related articles