I implemented the micro post search function by referring to the following site, but an error occurred during Rails test.
Reference URL: https://yukitoku-sw.hatenablog.com/entry/2019/11/10/001418

↓ Error details

test_micropost_interface # MicropostsInterfaceTest (1.63s)
ActionView :: Template :: Error: ActionView :: Template :: Error: No Ransack :: Search object was provided to search_form_for!
            app/views/shared/_microposts_search.html.erb: 3: in `_app_views_shared__microposts_search_html_erb___4334420189547037187_49418860'
            app/views/static_pages/home.html.erb: 16: in `_app_views_static_pages_home_html_erb___1981986679562933160_58706460'
            app/controllers/microposts_controller.rb: 12: in `create'
            test/integration/microposts_interface_test.rb: 15: in `block (2 levels) in<class: MicropostsInterfaceTest>'
            test/integration/microposts_interface_test.rb: 14: in `block in<class: MicropostsInterfaceTest>'

I'm in trouble because I don't know which part to fix, and I would appreciate it if anyone knows about it.


  <% = search_form_for @q, url: @url do | f |%>  <% = f.label: content_cont,'Micropost Search'%>          <% = f.search_field: content_cont, placeholder: "Enter keyword ..", class:'form-control'%>    <span>      <% = f.submit'Search', class: "btn btn-primary"%>    </span>      <% end%>


<% if logged_in?%>        <section>    <% = render'shared/user_info'%>  </section>  <section>    <% = render'shared/stats'%>  </section>  <section>    <% = render'shared/micropost_form'%>  </section></aside>   Timeline     <% = render'shared/microposts_search'%>  <% = render'shared/feed'%>  <% else%> Welcome to the My first App       This is the home page for the
     Ruby on Rails Tutorial     sample application.
  <% = link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary"%><% end%>


class MicropostsController


class MicropostsInterfaceTest
  • Answer # 1

    There is no index action in controller.

    def index
        params [: q] || = {}
        @q = Micropost.racsac (params [: q])

    Please put in.
    Also, if you put this in, you'll probably get the following error:
    url: @urlWhat is it? Isn't @url defined?
    This is not necessary if you can go to the Micropost index when you search.