Home>
I want to search for photo titles
When you search, everything will be reflected in veiw.
The database stores photo titles in the text column.
File name
= text_field_tag: search, params [: keyword]
I added params [: keyword] to the search results, but all the search results were reflected and had no effect.
I don't think you can read the tweet.rb if statement well.
Please tell me the cause.
File name<tweets.controller.rb>
def search
@tweets = Tweet.search (params [: keyword])
end
file name<tweet.rb>
def self.search (search)
if search
Tweet.where ('text LIKE (?)', "% # {Search}%")
else
Tweet.all
end
end
file name<search.html.haml>
.top-page
.menu
= form_tag (tweets_searches_path, method: 'get') do
= text_field_tag: search
= submit_tag 'Search', name: nil
[email protected] tweets.each do | tweet |
.main-photo {style: "background-image: url (# {tweet.image});"}
file<routes.rb>
Rails.application.routes.draw do
devise_for: users
root to: "tweets # index"
namespace: tweets do
resources: searches, only:: index
end
resources: tweets do
resources: comments, only: [: create,: destroy]
end
resources: users, only:: show
end
File name
class TweetsController
-
Answer # 1
Related articles
- error when implementing search function using ransack in ruby on rails
- 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 - data is not stored when implementing the comment function
- ruby - [rails] implementation of search function
- ruby on rails - search function using rails jquery does not work
- ruby - how to implement the search function
- ruby - rails pagination function i want to display in alphabetical order
- 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 - i want to implement a function (destroy action) that can delete posted messages, but i am getting an active reco
- ruby - i want to receive and search with multiple params
- 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 on rails - i want to implement a report function, but i get an actioncontroller :: urlgenerationerror
- array - about the tag search function in ransack when i press the submit button, an error occurs
- ruby hash search
- ruby - i want to implement the "like" function, but i get "nomethoderror in messages # index" in the view fi
- java - spring boot search function
- java - spring boot search function sql is not reflected after submitting with characters
Related questions
- ruby - passing variables using render partial
- ruby - #i want to see a list of posts for that user on the user details page
- ruby - implementation of friendly forwarding
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby - about rails controller new action
- ruby - rails page does not open
- [ruby] i'm having trouble with nomethoderror
- ruby - [search function] acquisition of products associated with users
- ruby - even if each statement is used, the contents of the db cannot be displayed in order and an error occurs
- ruby - if i include the'omniauth-facebook'gem, do i need to install the'omniauth' gem as well?
Is the
text_field_tag: search
part ofsearch.html.haml
nottext_field_tag: keyword
?