Home>
I'm a rails beginner and I'm developing an original app.
When I implemented it using ransack's gem to introduce the search function, an error occurred.
When I press the search button, the show method works instead of the search method for some reason, and I don't know the cause.
There is an items table and a category table, and they form an association.
This time, I am implementing it because I want to output search results for each category of posted items.
Thank you.
ActiveRecord :: RecordNotFound in ItemsController # show
Couldn't find Item with'id' = search
Extracted source (around line # 69):
def set_item
@item = Item.find (params [: id])
end
Corresponding source code
apps/contorollers/items_controller.rb
class ItemsController</pre>
<p><br />
index.html.erb</p>
<pre><code><% = search_form_for @search, url: items_search_path do | f |%>
<% = f.label: category_name_eq,'Category:'%>
<% = f.collection_select: category_name_eq, @category_name,: name,: name%>
<br>
<% = f.submit'Search'%>
<% end%>
routes.rb
Rails.application.routes.draw do
root to: "items # index"
devise_for: users
resources: items
get'items/search'
end
What I tried
I wrote it in the search method using binding.pry, but it doesn't stop, so it seems that the search method is not working well.
Thank you.
-
Answer # 1
Related articles
- ruby on rails - [rails] i'm implementing a search function using form_with, but i'm having trouble with the search results not b
- ruby - [search function] acquisition of products associated with users
- ruby on rails 6 - [rails]'unfollow' function does not work * no error message
- ruby - [rails] implementation of search function
- ruby - an error occurred when implementing the micropost search function using ransack
- ruby on rails - error when implementing rails6 follow function
- ruby - i get an error in the view while implementing carriewave
- ruby on rails - cart function routing error cannot be resolved
- array - about the tag search function in ransack when i press the submit button, an error occurs
- error in callback function in php class
- ruby - i want to resolve the error statement "/ users/sign_up" in devise's no route matches [post]
- sass - i get a name error in ruby on rails
- error when implementing ar model in python
- ruby - i want to refactor the description to display the search results
- ruby - i can't log in with the user management function using devise
- ruby - about the error content displayed in "rails" rspec
- ruby - when i try to update rails, i get a routing error
- ruby on rails - error with automatic deployment by capistrano
- ruby on rails 5 - about lint/syntax error of rubocop
- ruby - [rspec] error in "dependent: destoy" test: how to resolve "validation failed"
Related questions
- ruby - passing variables using render partial
- ruby - [rails] implementation of sending registration completion email
- ruby - i want to install ffi gem
- ruby - about customizing pagination with rails6 kaminari
- ruby - error when bundle install gem :: ext :: builderror: error: failed to build gem native extension
- ruby - activerecord :: recordnotfound couldn't find user with'id'= # i want to check the error that id cannot be obtained
- ruby on rails sorting
- ruby - bootstrap image is not displayed
- ruby - escape character in environment variable
- how to view comments for posts in ruby on rails
I managed to solve it on my own.
Since the show method will inevitably work,
<% = search_form_for (@search, url: items_search_path, method :: search) do | f |%>
I specified the method in.
Then I got a Routing Error this time, so I solved it easily.
I felt like I was forced to do it, but it's a solution.
However, if anyone knows a solution that is not this solution, we are still looking for answers, so thank you.