LoginSignup
0
0

More than 5 years have passed since last update.

ransackでボタンを押すだけで検索したい!

Posted at
index_controller.rb
def toppage
 @search = Offer.ransack(params[:q])
 @result = @search.result
end
def search
 @search = Offer.ransack(params[:q])
 @result = @search.result
end

toppage.html.erb
<%= link_to 'クリックしてください', controller: "index", action: "search",q: {title_cont: '検索させたいワード'} %>
search.html.erb
<% @result.each do |result| %>
  表示したいものを表示...
<% 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