0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

searchアクション

Posted at

1.ルーティング設定をする(app - config - routes.rb)

     collection do
      get 'search'
     end

2.コントローラーに「searchアクション」を定義する( app - controllers - places_controller.rb)

 def search
  @places = Place.search(params[:keyword])
 end

3.モデルに、self.search(search)を設定する(app -models -place.rb)

 def self.search(search)
  if search != ""
  Place.where('name LIKE(?)', "%#{search}%")
 else
  Place.all
 end
end

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?