Home>
I am making an application for posting events, and I made it a specification to save categories and scales in the active hash. I was able to search for the event name in the event model column using the search function, but I cannot search for data using the active hash.
Error statement
ActiveRecord :: StatementInvalid in Events # search_event
Showing /Users/user/projects/asomemo/app/views/events/search_event.html.erb where line # 6 raised:
Mysql2 :: Error: Unknown column'category_id.name' in'where clause'
Extracted source (around line # 6):<% end%><% @ events.each do | event |%><% = render partial: "event", locals: {event: event}%><% end%>
An error occurred because there is no column for category_id.name in the event model
Target code
Event controller
class EventsController</pre>
<p>Event model</p>
<pre><code>class Event</pre>
<p>Event migration file</p>
<pre><code>class CreateEvents</pre>
<p>Search view</p>
<pre><code><% = form_with (url: search_event_events_path, local: true, method:: get, class: "search-form") do | form |%><% = form.text_field: keyword, placeholder: "Search for posts", class: "search-input"%><% = form.submit "search", class: "search-btn"%><% end%>
---------- What I went to ---------------
Change the column name to search for the event model
Event.where ('category_id LIKE (?)', "% # {Search}%")
You can search, but you can only search by id number. Therefore, the search process is described in the active hash model.
class Category
I mentioned it, but I couldn't search the category. How can I use the name data of the active hash in the searth method?
-
Answer # 1
Related articles
- ruby - is it possible to search categories with active hash?
- ruby - i want to know the reason for implementing it in a class method or module when solving an exercise
- ruby on rails - search function using rails jquery does not work
- ruby - i want to search the data of a nested model using ransack
- ruby - nomethoderror: undefined method `new'for: uglifier: symbol error on heroku deployment
- ruby on rails multiple keyword search i don't know how to write
- ruby - [rails] i want to create a page where the url does not change by redirect even if i enter a value and search like a site
- ruby on rails - [rails] i want to make it a helper method
- [ruby] "attr_accessor" i don't understand this method
- ruby - i want to receive and search with multiple params
- ruby - improvement of nomethoderror undefined method `paginate'
- error when implementing search function using ransack in ruby on rails
- ruby - rails i want to search by multiple keywords
- ruby on rails - search for related models
- ruby - the view of the search screen is not displayed
- ruby - how to implement the search function
- ruby hash search
- search - method ~ does not exist
- ruby - undefined method `save'for nil: nilclass cannot be resolved
Related questions
- ruby - passing variables using render partial
- ruby - deployment error on heroku
- ruby - output the total integer value held by each user
- ruby - destroy action does not respond
- ruby - how do you see the rails controller relative path? (carrierwave directory deleted)
- ruby - when deploying on capistrano, i get the error "access denied for user'ec2-user' @'localhost' (using password: no)&qu
- javascript - run multiple times with js + each do
- how to reflect the layout downloaded from the external site in ruby on rails?
- ruby - how nice! function routes do not pass well (relation) [rails]
Make the following declaration in model Event
extend ActiveHash :: Associations :: ActiveRecordExtensions