Hello, I have a layout: _navigation.html.erb, and in it a code for search:

<form class="navbar-form navbar-left"> <div class="form-group search_margin"> <%= form_tag film_sessions_path, :method => 'get', class:"navbar-form navbar-left" do %> <%= text_field_tag :search, params[:search], class:"form-control", placeholder:"Search" %> <%= submit_tag "Search", class:"btn btn-raised btn-primary" %> <% end %> <span class="material-input"></span></div> </form> 

Next in the controller film_sessions:

  def index @film_sessions = FilmSession.where(["session_name LIKE ?","%#{params[:search]}%"]) @film_sessions = FilmSession.where(["session_name LIKE ?","%#{params[:search]}%"]) end 

It turns out that the search only works on the film_sessions_path page. How to fasten it to any page of the site, so that when you click on the search button, you are redirected to film_sessions_path?

Shape markup

 <form class="navbar-form navbar-left"> <div class="form-group search_margin"> <input name="utf8" type="hidden" value="✓"> <input type="text" name="search" id="search" value="фыв" class="form-control" placeholder="Search"> <input type="submit" name="commit" value="Search" class="btn btn-raised btn-primary"> <span class="material-input"></span> <span class="material-input"></span> </div> </form> 
  • It turns out that the search only works on the film_sessions_path page. - chegoy? - D-side
  • On other pages, it just reloads and adds to their address:? Utf8 = ✓ & search = fv & commit = Search - Maxim Cherevatov
  • Show the markup of the rendered as a result of this form. - D-side
  • Updated the question) - Maxim Cherevatov
  • Interesting, however, things. And if pry inside the view and look at film_sessions_path , what is it? - D-side

1 answer 1

And why is the html <form> and in it the form_tag ? The latter adds the same form tag and the HTML standards do not allow their nesting. That browser is trying to "fix". That's right, apparently so:

 <%= form_tag film_sessions_path, :method => 'get', class:"navbar-form navbar-left" do %> <div class="form-group search_margin"> <%= text_field_tag :search, params[:search], class:"form-control", placeholder:"Search" %> <%= submit_tag "Search", class:"btn btn-raised btn-primary" %> <span class="material-input"></span> </div> <% end %> 
  • Thank you, really!) - Maxim Cherevatov