ransack search form in header partial: No Ransack::Search object was provided to search_form_for

前端 未结 3 759
长情又很酷
长情又很酷 2021-02-04 14:30

First of all, I\'m new to RoR, so the answer may be obvious, in which case I apologize. I\'ve looked around and haven\'t found anything that helps.

I\'m trying to have

3条回答
  •  伪装坚强ぢ
    2021-02-04 14:54

    No, you do not need to edit all your controllers.

    You can use ApplicationController for all your "common" controller needs. Read up on it in the guides http://guides.rubyonrails.org/action_controller_overview.html and the API docs http://api.rubyonrails.org/classes/ActionController/Base.html

    The key here is, when you generated your new rails app, you'll notice it created the file .../app/controllers/action_controller.rb and that class derives from ActionController::Base. Then, if you again use the rails generator to create a controller for your app, you'll notice your new controller class derives from ApplicationController (not ::Base). That means that the application_controller.rb is the parent controller class for your app. That means everything in it is available to all your app controllers. It's easy to abuse, so be judicious.

提交回复
热议问题