ruby on rails 4 - Show filterrific form in different controller view -


i want show filterrific form in landing page of application. how make form respond different controller action?

the code below filterrific sample application. want search , filter student model. , want users of application able search students home page of welcome controller.

<%# app/views/students/index.html.erb %>  <h1>students</h1>        <%= form_for_filterrific @filterrific |f| %>    <div>      search      <%# give search field 'filterrific-periodically-observed' class live updates %>      <%= f.text_field(        :search_query,        class: 'filterrific-periodically-observed'      ) %>    </div>    <div>      country      <%= f.select(        :with_country_id,        @filterrific.select_options[:with_country_id],        { include_blank: '- -' }      ) %>    </div>    <div>      registered after      <%= f.text_field(:with_created_at_gte, class: 'js-datepicker') %>    </div>    <div>      sorted      <%= f.select(:sorted_by, @filterrific.select_options[:sorted_by]) %>    </div>    <div>      <%= link_to(        'reset filters',        reset_filterrific_url,      ) %>    </div>    <%# add automated spinner form when list refreshed %>    <%= render_filterrific_spinner %>  <% end %>    <%= render(    partial: 'students/list',    locals: { students: @students }  ) %>

this code works because have filterrific setup index.html page of students controller. want show form in home page of welcome controller when users put filter criteria , search take them students index page search results. how make work there? changes should make form?

check out page sample application. example filterrific application

thanks help.

you need following desired behavior:

  • override :url option on form_for_filterrific submits studentscontroller#index instead of home page.
  • turn off ajax auto submit , submit form manually. ajax behavior added based on form's id attr. easiest way turn off auto ajax submit change id.
  • add submit button form manual submission.

here relevant code:

<%= form_for_filterrific(       @filterrific,        url: students_path,        html: { id: :manual_filterrific_form }     ) |f| %>   [form inputs go here ...]   <%= f.submit "show students" %> <% end %> 

now form displayed on home page. when user sets filters , clicks "show students", taken studentscontroller#index , see filtered list of students.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -