Ransack: how to use ransack when not using erb front end

Created on 16 Feb 2016  路  2Comments  路  Source: activerecord-hackery/ransack

I am panning to do ransack search using angular in rails. So I have the below doubt now
In a normal rails app which uses ransack we do like below in a form.

<%= search_form_for @search, url: search_path, id: "listings_search" do |f| %>
      <div class="col-md-2">
        <%= text_field_tag :search, params[:search], placeholder: "Where are you going?", id: "autocomplete-input", class: "form-control" %>
      </div>
      <div class="col-md-2">
        <%= text_field_tag :start_date, params[:start_date],
                           placeholder: "Start Date", class: "form-control" %>
      </div>
      <div class="col-md-2">
        <%= text_field_tag :end_date, params[:end_date],
                           placeholder: "End Date", class: "form-control" %>
      </div>
      <div class="col-md-2">
        <%= f.text_field :price_gteq, placeholder: "Min Price",
                         class: "form-control" %>
      </div>
      <div class="col-md-2">
        <%= f.text_field :price_lteq, placeholder: "Max Price",
                         class: "form-control" %>
      </div>
      <div class="col-md-2">
        <%= f.submit "Search", class: "btn btn-primary btn-md" %>
      </div>
  <% end %>

But how to make this work when using angular? Is there anything specific I need to do instead of the search_form_for, gteq etc when making this form work in angular?

Most helpful comment

Nothing special. See what the posted inputs look like, and make your Javascript look like that. Basic Searching is described in the wiki.

You can also try this format if you need more complex control:

https://github.com/activerecord-hackery/ransack/blob/master/spec/ransack/search_spec.rb#L123

The structure is:

  • g: grouping (list of conditions)

    • m: combinator ('and' / 'or')

    • c: condition

    • a: attribute (prefix with association name if needed)

    • p: predicate (eq, lt, gt, etc.)

    • v: value

These can be nested and combined too. Hope this helps.

All 2 comments

Nothing special. See what the posted inputs look like, and make your Javascript look like that. Basic Searching is described in the wiki.

You can also try this format if you need more complex control:

https://github.com/activerecord-hackery/ransack/blob/master/spec/ransack/search_spec.rb#L123

The structure is:

  • g: grouping (list of conditions)

    • m: combinator ('and' / 'or')

    • c: condition

    • a: attribute (prefix with association name if needed)

    • p: predicate (eq, lt, gt, etc.)

    • v: value

These can be nested and combined too. Hope this helps.

@avit It did..Thank you..

Was this page helpful?
0 / 5 - 0 ratings