We are creating an application that allows you to search for restaurants based on three search conditions (genre, region, and tag).
Genres/regions are saved as columns in the shop table.
The tag is
shop table-shop_tag_relation intermediate table-tag table
It is saved using an intermediate table like.
NoMethodError in ShopsController # search undefined method `to_i'for ["", "1"]: Array
If i enter the conditions and press the submit button, the above error will occur.Corresponding source code
Since genre and prefecture want to search for a match, use the helper method _eq
Use the helper method _cont because the tag wants to search everything that contains the specified value
# index.html.erb <% = search_form_for @p, url: shops_search_path do | f |%> <% = f.label: genre_eq,'genre'%> <% = f.collection_select: genre_id_eq, Genre.all,: id,: name, include_blank:'not specified'%> <br> <% = f.label: prefecture_eq,'location'%> <% = f.collection_select: prefecture_id_eq, Prefecture.all,: id,: name, include_blank:'not specified'%> <br> <% = f.label: shop_tag_relations_tag_id_cont,'Commitment condition'%> <% = f.collection_check_boxes: shop_tag_relations_tag_id_cont, Tag.all,: id,: name%> <br> <% = f.submit'Search'%> <% end%>
The strong parameter is set to pass anything temporarily.
What I tried
I tried: shop_tag_relations_tag_ids_cont to submit the parameters in an array in the search form, but it didn't work ...
I've been addicted to it for a whole day.
By all means, thanks for your support.
Please provide more detailed information here.
Answer # 1
Has_many: tags in the model Shop, right?
f.collection_check_boxes: shop_tag_relations_tag_id_cont, Tag.all,: id,: name%>
By the way
: tag_name_contIt seems to be. Just in case, please try the plural form.
- i want to make a multiple search function with laravel
- cakephp - i want to ambiguously search array values with multiple conditions
- assign java array to function
- pass the array to the function in the sort program and sort it by the function side
- dart - how to use contains with database + search function
- [swiftui] i want to create a textfield with a search function
- ruby - rails that can't search by date with ransack
- ruby on rails 5 - i want to make a search that uses ransack to enter half-width alphanumeric characters in the input as well as
- ruby on rails: can you search with ransack and where?
- ruby - [rails] implementation of search function using form_tag
- php - i want to implement laravel search function
- ruby - in the advanced search function that uses rakuten api, i want to enter the default value when performing a search with in
- java - i want to create a search function in spring
- ES6 function and array usage example analysis
- java - i want to implement a search function in spring
- ruby - about implementing search function with rails
- behavior when a char array is passed to a c function and treated as a pointer
- ruby - i got "mysql2 :: error :: connectionerror: plugin caching_sha2_password could not be loaded "
- cannot create database with docker
- ruby - nothing is displayed even if docker attaches and i cannot debug [rails 6]
- unknown mysql server host'db' (0)
- aws - about rails app ci to aws
- ruby on rails - unable to access localhost with rails6 and docker
- ruby - "volumes" described in docker-composeyml
- i want to build rails with docker alpine, but i don't know how to find the required package