No Ransack::Search object was provided to search_form_for

前端 未结 2 736
难免孤独
难免孤独 2021-01-06 06:23

I realise other people have asked about this error but it was to do with a different circumstance.

I have added the Ransack gem for rails 4 and bundled installed wi

2条回答
  •  日久生厌
    2021-01-06 06:34

    Nicolas was right in that the error is coming from @q only being initialized when the request contains a "q" parameter. Which is why before you submit the form you get the error (no "q" parameter).

    another way to get around this is initializing @q

    in your application_controller

    def set_search
    @q=Recipe.search(params[:q])
    end
    

    in your recipes_controller before_filter :set_search

提交回复
热议问题